* docs: New V3 docs for new API * fix: Prefer Wide-Angle unless explicitly opted-out * docs: Update DEVICES * Finish Devices docs * Switch links * Revert "Switch links" This reverts commit 06f196ae0e67787cbd5768e125be6d0a3cb5bbc9. * docs: New LIFECYCLE * docs: New CAPTURING docs * Update Worklets links * docs: Update TROUBLESHOOTING and ZOOMING * fix: Update `getAvailableCameraDevices()` usages * docs: Update FORMATS * Update Errors.kt * docs: Fix broken links * docs: Update references to old hooks * docs: Create Frame Processor Tips * docs: Auto-dark mode * fix: Fix FPS filter * feat: Add `'max'` flag to format filter * fix: Use loop * fix: Fix bug in `getCameraFormat` * fix: Find best aspect ratio as well * fix: Switch between formats on FPS change * Update FRAME_PROCESSOR_PLUGIN_LIST.mdx * Add FPS graph explanation * feat: Support HDR filter * docs: Add HDR docs * docs: Add Video Stabilization * docs: Update Skia docs * Skia links * Add Skia labels * Update SKIA_FRAME_PROCESSORS.mdx * docs: Add Performance * Update some wording * Update headers / and zoom * Add examples for devices * fix highlights * fix: Expose `Frame` * docs: Update FP docs * Update links * Update FRAME_PROCESSOR_CREATE_PLUGIN_IOS.mdx
106 lines
3.1 KiB
Plaintext
106 lines
3.1 KiB
Plaintext
---
|
|
id: errors
|
|
title: Camera Errors
|
|
sidebar_label: Camera Errors
|
|
---
|
|
|
|
import useBaseUrl from '@docusaurus/useBaseUrl';
|
|
|
|
<div>
|
|
<img align="right" width="283" src={useBaseUrl("img/example_error.png")} />
|
|
</div>
|
|
|
|
## Why?
|
|
|
|
Since the Camera library is quite big, there is a lot that can "go wrong". VisionCamera provides thoroughly typed errors to help you quickly identify the cause and fix the problem.
|
|
|
|
```ts
|
|
switch (error.code) {
|
|
case "device/configuration-error":
|
|
// prompt user
|
|
break
|
|
case "device/microphone-unavailable":
|
|
// ask for permission
|
|
break
|
|
case "capture/recording-in-progress":
|
|
// stop recording
|
|
break
|
|
default:
|
|
console.error(error)
|
|
break
|
|
}
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
See [Troubleshooting](troubleshooting) if you're having "weird issues".
|
|
|
|
## The Error types
|
|
|
|
The `CameraError` type is a baseclass type for all other errors and provides the following properties:
|
|
|
|
* `code`: A typed code in the form of `{domain}/{code}` that can be used to quickly identify and group errors
|
|
* `message`: A non-localized message text that provides a more information and context about the error and possibly problematic values.
|
|
* `cause?`: An `ErrorWithCause` instance that provides information about the cause of the error. (Optional)
|
|
* `cause.message`: The message of the error that caused the camera error.
|
|
* `cause.code?`: The native error's error-code. (iOS only)
|
|
* `cause.domain?`: The native error's domain. (iOS only)
|
|
* `cause.details?`: More dictionary-style information about the cause. (iOS only)
|
|
* `cause.stacktrace?`: A native Java stacktrace for the cause. (Android only)
|
|
* `cause.cause?`: The cause that caused this cause. (Recursive) (Optional)
|
|
|
|
:::note
|
|
See [the `CameraError.ts` file](https://github.com/mrousavy/react-native-vision-camera/blob/main/package/src/CameraError.ts) for a list of all possible error codes
|
|
:::
|
|
|
|
### Runtime Errors
|
|
|
|
The `CameraRuntimeError` represents any kind of error that occured while mounting the Camera view, or an error that occured during the runtime.
|
|
|
|
The `<Camera />` UI Component provides an `onError` function that will be invoked every time an unexpected runtime error occured.
|
|
|
|
```tsx
|
|
function App() {
|
|
const onError = useCallback((error: CameraRuntimeError) => {
|
|
console.error(error)
|
|
}, [])
|
|
|
|
return <Camera onError={onError} {...cameraProps} />
|
|
}
|
|
```
|
|
|
|
### Capture Errors
|
|
|
|
The `CameraCaptureError` represents any kind of error that occured only while capturing a photo or recording a video.
|
|
|
|
```tsx
|
|
function App() {
|
|
const camera = useRef<Camera>(null)
|
|
|
|
// called when the user presses a "capture" button
|
|
const onPress = useCallback(() => {
|
|
try {
|
|
const photo = await camera.current.takePhoto()
|
|
} catch (e) {
|
|
if (e instanceof CameraCaptureError) {
|
|
switch (e.code) {
|
|
case "capture/file-io-error":
|
|
console.error("Failed to write photo to disk!")
|
|
break
|
|
default:
|
|
console.error(e)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}, [camera])
|
|
|
|
return <Camera ref={camera} {...cameraProps} />
|
|
}
|
|
```
|
|
|
|
|
|
<br />
|
|
|
|
#### 🚀 Next section: [Troubleshooting](troubleshooting)
|