ESLint autofix

This commit is contained in:
Marc Rousavy
2021-02-20 17:07:10 +01:00
parent 50509200aa
commit dc2be934f6
22 changed files with 439 additions and 690 deletions

View File

@@ -1,42 +1,40 @@
export type PermissionError =
| "permission/microphone-permission-denied"
| "permission/camera-permission-denied";
export type PermissionError = 'permission/microphone-permission-denied' | 'permission/camera-permission-denied';
export type ParameterError =
| "parameter/invalid-parameter"
| "parameter/unsupported-os"
| "parameter/unsupported-output"
| "parameter/unsupported-input"
| "parameter/invalid-combination";
| 'parameter/invalid-parameter'
| 'parameter/unsupported-os'
| 'parameter/unsupported-output'
| 'parameter/unsupported-input'
| 'parameter/invalid-combination';
export type DeviceError =
| "device/configuration-error"
| "device/no-device"
| "device/invalid-device"
| "device/torch-unavailable"
| "device/microphone-unavailable"
| "device/low-light-boost-not-supported"
| "device/focus-not-supported"
| "device/camera-not-available-on-simulator";
| 'device/configuration-error'
| 'device/no-device'
| 'device/invalid-device'
| 'device/torch-unavailable'
| 'device/microphone-unavailable'
| 'device/low-light-boost-not-supported'
| 'device/focus-not-supported'
| 'device/camera-not-available-on-simulator';
export type FormatError =
| "format/invalid-fps"
| "format/invalid-hdr"
| "format/invalid-low-light-boost"
| "format/invalid-format"
| "format/invalid-preset";
export type SessionError = "session/camera-not-ready";
| 'format/invalid-fps'
| 'format/invalid-hdr'
| 'format/invalid-low-light-boost'
| 'format/invalid-format'
| 'format/invalid-preset';
export type SessionError = 'session/camera-not-ready';
export type CaptureError =
| "capture/invalid-photo-format"
| "capture/encoder-error"
| "capture/muxer-error"
| "capture/recording-in-progress"
| "capture/no-recording-in-progress"
| "capture/file-io-error"
| "capture/create-temp-file-error"
| "capture/invalid-photo-codec"
| "capture/not-bound-error"
| "capture/capture-type-not-supported"
| "capture/unknown";
export type SystemError = "system/no-camera-manager";
export type UnknownError = "unknown/unknown";
| 'capture/invalid-photo-format'
| 'capture/encoder-error'
| 'capture/muxer-error'
| 'capture/recording-in-progress'
| 'capture/no-recording-in-progress'
| 'capture/file-io-error'
| 'capture/create-temp-file-error'
| 'capture/invalid-photo-codec'
| 'capture/not-bound-error'
| 'capture/capture-type-not-supported'
| 'capture/unknown';
export type SystemError = 'system/no-camera-manager';
export type UnknownError = 'unknown/unknown';
export interface ErrorWithCause {
/**
@@ -69,15 +67,7 @@ export interface ErrorWithCause {
cause?: ErrorWithCause;
}
type CameraErrorCode =
| PermissionError
| ParameterError
| DeviceError
| FormatError
| SessionError
| CaptureError
| SystemError
| UnknownError;
type CameraErrorCode = PermissionError | ParameterError | DeviceError | FormatError | SessionError | CaptureError | SystemError | UnknownError;
/**
* Represents any kind of error that occured in the Camera View Module.
@@ -98,7 +88,7 @@ class CameraError<TCode extends CameraErrorCode> extends Error {
}
constructor(code: TCode, message: string, cause?: ErrorWithCause) {
super(`[${code}]: ${message}${cause ? ` (Cause: ${cause.message})` : ""}`);
super(`[${code}]: ${message}${cause ? ` (Cause: ${cause.message})` : ''}`);
this._code = code;
this._message = message;
this._cause = cause;
@@ -114,58 +104,44 @@ export class CameraCaptureError extends CameraError<CaptureError> {}
* Represents any kind of error that occured in the Camera View Module.
*/
export class CameraRuntimeError extends CameraError<
| PermissionError
| ParameterError
| DeviceError
| FormatError
| SessionError
| SystemError
| UnknownError
PermissionError | ParameterError | DeviceError | FormatError | SessionError | SystemError | UnknownError
> {}
export const isErrorWithCause = (error: unknown): error is ErrorWithCause =>
typeof error === "object" &&
typeof error === 'object' &&
error != null &&
// @ts-expect-error error is still unknown
typeof error.message === "string" &&
typeof error.message === 'string' &&
// @ts-expect-error error is still unknown
(typeof error.stacktrace === "string" || error.stacktrace == null) &&
(typeof error.stacktrace === 'string' || error.stacktrace == null) &&
// @ts-expect-error error is still unknown
(isErrorWithCause(error.cause) || error.cause == null);
const isCameraErrorJson = (
error: unknown
): error is { code: string; message: string; cause?: ErrorWithCause } =>
typeof error === "object" &&
const isCameraErrorJson = (error: unknown): error is { code: string; message: string; cause?: ErrorWithCause } =>
typeof error === 'object' &&
error != null &&
// @ts-expect-error error is still unknown
typeof error.code === "string" &&
typeof error.code === 'string' &&
// @ts-expect-error error is still unknown
typeof error.message === "string" &&
typeof error.message === 'string' &&
// @ts-expect-error error is still unknown
(typeof error.cause === "object" || error.cause == null);
(typeof error.cause === 'object' || error.cause == null);
/**
* Tries to parse an error coming from native to a typed JS camera error.
* @param nativeError The native error instance. This is a JSON in the legacy native module architecture.
* @returns A `CameraRuntimeError` or `CameraCaptureError`, or the nativeError if it's not parsable
*/
export const tryParseNativeCameraError = <T>(
nativeError: T
): (CameraRuntimeError | CameraCaptureError) | T => {
export const tryParseNativeCameraError = <T>(nativeError: T): (CameraRuntimeError | CameraCaptureError) | T => {
if (isCameraErrorJson(nativeError)) {
if (nativeError.code.startsWith("capture")) {
return new CameraCaptureError(
nativeError.code as CaptureError,
nativeError.message,
nativeError.cause
);
if (nativeError.code.startsWith('capture')) {
return new CameraCaptureError(nativeError.code as CaptureError, nativeError.message, nativeError.cause);
} else {
return new CameraRuntimeError(
// @ts-expect-error the code is string, we narrow it down to TS union.
nativeError.code,
nativeError.message,
nativeError.cause
nativeError.cause,
);
}
} else {