chore: Remove semicolons (#1846)
* chore: Disable `semi` in Prettier * chore: Format w/o semi * Remove more `;` * Lint example * More ;
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
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-combination'
|
||||
export type DeviceError =
|
||||
| 'device/configuration-error'
|
||||
| 'device/no-device'
|
||||
@@ -14,21 +14,21 @@ export type DeviceError =
|
||||
| 'device/pixel-format-not-supported'
|
||||
| 'device/low-light-boost-not-supported'
|
||||
| 'device/focus-not-supported'
|
||||
| 'device/camera-not-available-on-simulator';
|
||||
| 'device/camera-not-available-on-simulator'
|
||||
export type FormatError =
|
||||
| 'format/invalid-fps'
|
||||
| 'format/invalid-hdr'
|
||||
| 'format/incompatible-pixel-format-with-hdr-setting'
|
||||
| 'format/invalid-low-light-boost'
|
||||
| 'format/invalid-format'
|
||||
| 'format/invalid-color-space';
|
||||
| 'format/invalid-color-space'
|
||||
export type SessionError =
|
||||
| 'session/camera-not-ready'
|
||||
| 'session/camera-cannot-be-opened'
|
||||
| 'session/camera-has-been-disconnected'
|
||||
| 'session/audio-session-setup-failed'
|
||||
| 'session/audio-in-use-by-other-app'
|
||||
| 'session/audio-session-failed-to-activate';
|
||||
| 'session/audio-session-failed-to-activate'
|
||||
export type CaptureError =
|
||||
| 'capture/invalid-photo-format'
|
||||
| 'capture/encoder-error'
|
||||
@@ -50,13 +50,13 @@ export type CaptureError =
|
||||
| 'capture/video-not-enabled'
|
||||
| 'capture/photo-not-enabled'
|
||||
| 'capture/aborted'
|
||||
| 'capture/unknown';
|
||||
| 'capture/unknown'
|
||||
export type SystemError =
|
||||
| 'system/camera-module-not-found'
|
||||
| 'system/no-camera-manager'
|
||||
| 'system/frame-processors-unavailable'
|
||||
| 'system/view-not-found';
|
||||
export type UnknownError = 'unknown/unknown';
|
||||
| 'system/view-not-found'
|
||||
export type UnknownError = 'unknown/unknown'
|
||||
|
||||
/**
|
||||
* Represents a JSON-style error cause. This contains native `NSError`/`Throwable` information, and can have recursive {@linkcode ErrorWithCause.cause | .cause} properties until the ultimate cause has been found.
|
||||
@@ -68,42 +68,42 @@ export interface ErrorWithCause {
|
||||
* * iOS: `NSError.code`
|
||||
* * Android: N/A
|
||||
*/
|
||||
code?: number;
|
||||
code?: number
|
||||
/**
|
||||
* The native error's domain.
|
||||
*
|
||||
* * iOS: `NSError.domain`
|
||||
* * Android: N/A
|
||||
*/
|
||||
domain?: string;
|
||||
domain?: string
|
||||
/**
|
||||
* The native error description
|
||||
*
|
||||
* * iOS: `NSError.message`
|
||||
* * Android: `Throwable.message`
|
||||
*/
|
||||
message: string;
|
||||
message: string
|
||||
/**
|
||||
* Optional additional details
|
||||
*
|
||||
* * iOS: `NSError.userInfo`
|
||||
* * Android: N/A
|
||||
*/
|
||||
details?: Record<string, unknown>;
|
||||
details?: Record<string, unknown>
|
||||
/**
|
||||
* Optional Java stacktrace
|
||||
*
|
||||
* * iOS: N/A
|
||||
* * Android: `Throwable.stacktrace.toString()`
|
||||
*/
|
||||
stacktrace?: string;
|
||||
stacktrace?: string
|
||||
/**
|
||||
* Optional additional cause for nested errors
|
||||
*
|
||||
* * iOS: N/A
|
||||
* * Android: `Throwable.cause`
|
||||
*/
|
||||
cause?: ErrorWithCause;
|
||||
cause?: ErrorWithCause
|
||||
}
|
||||
|
||||
type CameraErrorCode =
|
||||
@@ -114,42 +114,42 @@ type CameraErrorCode =
|
||||
| SessionError
|
||||
| CaptureError
|
||||
| SystemError
|
||||
| UnknownError;
|
||||
| UnknownError
|
||||
|
||||
/**
|
||||
* Represents any kind of error that occured in the {@linkcode Camera} View Module.
|
||||
*/
|
||||
class CameraError<TCode extends CameraErrorCode> extends Error {
|
||||
private readonly _code: TCode;
|
||||
private readonly _message: string;
|
||||
private readonly _cause?: ErrorWithCause;
|
||||
private readonly _code: TCode
|
||||
private readonly _message: string
|
||||
private readonly _cause?: ErrorWithCause
|
||||
|
||||
public get code(): TCode {
|
||||
return this._code;
|
||||
return this._code
|
||||
}
|
||||
public get message(): string {
|
||||
return this._message;
|
||||
return this._message
|
||||
}
|
||||
public get cause(): Error | undefined {
|
||||
const c = this._cause;
|
||||
if (c == null) return undefined;
|
||||
return new Error(`[${c.code}]: ${c.message}`);
|
||||
const c = this._cause
|
||||
if (c == null) return undefined
|
||||
return new Error(`[${c.code}]: ${c.message}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(code: TCode, message: string, cause?: ErrorWithCause) {
|
||||
super(`[${code}]: ${message}${cause != null ? ` (Cause: ${cause.message})` : ''}`);
|
||||
super.name = code;
|
||||
super.message = message;
|
||||
this._code = code;
|
||||
this._message = message;
|
||||
this._cause = cause;
|
||||
super(`[${code}]: ${message}${cause != null ? ` (Cause: ${cause.message})` : ''}`)
|
||||
super.name = code
|
||||
super.message = message
|
||||
this._code = code
|
||||
this._message = message
|
||||
this._cause = cause
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
return `[${this.code}]: ${this.message}`;
|
||||
return `[${this.code}]: ${this.message}`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ export const isErrorWithCause = (error: unknown): error is ErrorWithCause =>
|
||||
// @ts-expect-error error is still unknown
|
||||
(typeof error.stacktrace === 'string' || error.stacktrace == null) &&
|
||||
// @ts-expect-error error is still unknown
|
||||
(isErrorWithCause(error.cause) || error.cause == null);
|
||||
(isErrorWithCause(error.cause) || error.cause == null)
|
||||
|
||||
const isCameraErrorJson = (error: unknown): error is { code: string; message: string; cause?: ErrorWithCause } =>
|
||||
typeof error === 'object' &&
|
||||
@@ -192,7 +192,7 @@ const isCameraErrorJson = (error: unknown): error is { code: string; message: st
|
||||
// @ts-expect-error error is still unknown
|
||||
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.
|
||||
@@ -203,16 +203,16 @@ const isCameraErrorJson = (error: unknown): error is { code: string; message: st
|
||||
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);
|
||||
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,
|
||||
);
|
||||
)
|
||||
}
|
||||
} else {
|
||||
return nativeError;
|
||||
return nativeError
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user