From 98f1961fa7a0f0f6ac3b1c6c2248f4ca63864c45 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Mon, 27 Sep 2021 14:44:09 +0200 Subject: [PATCH] fix: Throw `'frame-processor/unavailable'` error instead of normal JS Error (#461) * Throw `'frame-processor/unavailable'` error instead of normal JS Error * Update CameraDevice.ts --- src/Camera.tsx | 3 ++- src/CameraDevice.ts | 3 +-- src/CameraError.ts | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Camera.tsx b/src/Camera.tsx index 1322d4b..5270a11 100644 --- a/src/Camera.tsx +++ b/src/Camera.tsx @@ -348,7 +348,8 @@ export class Camera extends React.PureComponent { private assertFrameProcessorsEnabled(): void { // @ts-expect-error JSI functions aren't typed if (global.setFrameProcessor == null || global.unsetFrameProcessor == null) { - throw new Error( + throw new CameraRuntimeError( + 'frame-processor/unavailable', 'Frame Processors are not enabled. See https://mrousavy.github.io/react-native-vision-camera/docs/guides/troubleshooting', ); } diff --git a/src/CameraDevice.ts b/src/CameraDevice.ts index e2cc43f..7bd73ad 100644 --- a/src/CameraDevice.ts +++ b/src/CameraDevice.ts @@ -33,10 +33,9 @@ export const parsePhysicalDeviceTypes = ( const hasWide = physicalDeviceTypes.includes('wide-angle-camera'); const hasUltra = physicalDeviceTypes.includes('ultra-wide-angle-camera'); const hasTele = physicalDeviceTypes.includes('telephoto-camera'); + if (hasTele && hasWide && hasUltra) return 'triple-camera'; - if (hasWide && hasUltra) return 'dual-wide-camera'; - if (hasWide && hasTele) return 'dual-camera'; throw new Error(`Invalid physical device type combination! ${physicalDeviceTypes.join(' + ')}`); diff --git a/src/CameraError.ts b/src/CameraError.ts index 8c6a885..a379550 100644 --- a/src/CameraError.ts +++ b/src/CameraError.ts @@ -15,6 +15,7 @@ export type DeviceError = | 'device/low-light-boost-not-supported' | 'device/focus-not-supported' | 'device/camera-not-available-on-simulator'; +export type FrameProcessorError = 'frame-processor/unavailable'; export type FormatError = | 'format/invalid-fps' | 'format/invalid-hdr' @@ -98,6 +99,7 @@ type CameraErrorCode = | PermissionError | ParameterError | DeviceError + | FrameProcessorError | FormatError | SessionError | CaptureError @@ -152,7 +154,7 @@ export class CameraCaptureError extends CameraError {} * See the ["Camera Errors" documentation](https://mrousavy.github.io/react-native-vision-camera/docs/guides/errors) for more information about Camera Errors. */ export class CameraRuntimeError extends CameraError< - PermissionError | ParameterError | DeviceError | FormatError | SessionError | SystemError | UnknownError + PermissionError | ParameterError | DeviceError | FormatError | FrameProcessorError | SessionError | SystemError | UnknownError > {} /**