/**
* Helper type to extract type generic parameter.
*/
type ExtractName
= P extends NamedError ? T : never;
/**
* All errors are expected to have "Error" suffix.
*/
type ErrorName = `${string}Error`;
type NamedError = Error & {
name: Name;
};
/**
* Creates error factory that ensures Error.prototype.name field value.
*
* NOTE: exported only for unit tests.
*
* @param name Error name.
* @returns Error factory function.
* @internal
*/
export declare function namedError = never, TName extends ErrorName = ExtractName>(name: TName): (message: string, cause?: unknown) => TError;
export type LegalError = NamedError<"LegalError">;
/** @internal */
export declare const legalError: (message: string, cause?: unknown) => LegalError;
export type LensContentValidationError = NamedError<"LensContentValidationError">;
/** @internal */
export declare const lensContentValidationError: (message: string, cause?: unknown) => LensContentValidationError;
/**
* This error occurs if a Lens cannot be applied to the session, and is the rejection reason of
* {@link CameraKitSession.applyLens}.
*
* If the Lens's own script threw while starting up, the script's error is behind this one; see
* {@link LensScriptError}.
*/
export type LensError = NamedError<"LensError">;
/** @internal */
export declare const lensError: (message: string, cause?: unknown) => LensError;
export type CameraKitSourceError = NamedError<"CameraKitSourceError">;
/** @internal */
export declare const cameraKitSourceError: (message: string, cause?: unknown) => CameraKitSourceError;
/**
* The error triggered when a lens prompts the user to select an image, but the image fails to be successfully delivered
* to the lens.
*/
export type LensImagePickerError = NamedError<"LensImagePickerError">;
/** @internal */
export declare const lensImagePickerError: (message: string, cause?: unknown) => LensImagePickerError;
export type CacheKeyNotFoundError = NamedError<"CacheKeyNotFoundError">;
/** @internal */
export declare const cacheKeyNotFoundError: (message: string, cause?: unknown) => CacheKeyNotFoundError;
/**
* Thrown by {@link bootstrapCameraKit} if provided configuration is invalid.
*
* @category Bootstrapping and Configuration
*/
export type ConfigurationError = NamedError<"ConfigurationError">;
/** @internal */
export declare const configurationError: (message: string, cause?: unknown) => ConfigurationError;
export type WebGLError = NamedError<"WebGLError">;
/** @internal */
export declare const webGLError: (message: string, cause?: unknown) => WebGLError;
export type BenchmarkError = NamedError<"BenchmarkError">;
/** @internal */
export declare const benchmarkError: (message: string, cause?: unknown) => BenchmarkError;
/**
* Thrown by {@link bootstrapCameraKit} when the current platform is not supported by CameraKit.
*
* This can happen if the browser doesn't support a required feature (e.g. WebGL).
*
* @category Bootstrapping and Configuration
*/
export type PlatformNotSupportedError = NamedError<"PlatformNotSupportedError">;
/** @internal */
export declare const platformNotSupportedError: (message: string, cause?: unknown) => PlatformNotSupportedError;
/**
* This error occurs if a Lens is unable to continue rendering.
*
* If this error occurs, Camera Kit automatically removes the Lens from the session.
* It's always a good idea to handle this error and update the user experience accordingly.
* For example, you could remove the faulty Lens from your Lens selection UI.
*
* ```ts
* cameraKitSession.events.addEventListener('error', ({ detail }) => {
* if (detail.error.name === 'LensExecutionError') {
* console.log(`Lens ${detail.lens.name} encountered an error and was removed. Please pick a different lens.`)
* }
* })
* ```
*
* If the Lens's own script threw while running, the script's error is behind this one; see {@link LensScriptError}.
*/
export type LensExecutionError = NamedError<"LensExecutionError">;
/** @internal */
export declare const lensExecutionError: (message: string, cause?: unknown) => LensExecutionError;
/**
* The error a Lens script threw, for example a `TypeError` in one of its `.js` files.
*
* Camera Kit never surfaces this error directly. It is the `cause` at the end of the chain behind the error you
* actually receive, and which one you receive depends on when the script failed:
*
* - **Before `applyLens` resolved.** The script threw while starting up, typically in `onAwake` or top-level code.
* `applyLens` rejects with a {@link LensError} and the Lens is not applied.
* - **After `applyLens` resolved.** The script threw while the Lens was running, typically in an event handler such
* as an update, tap, or delayed callback. Camera Kit removes the Lens and emits a {@link LensExecutionError} on
* the session's `error` event.
*
* Use {@link findLensScriptError} to retrieve it from either.
*
* - `message` is the script's error, e.g. `TypeError: cannot read property 'text' of undefined`.
* - `stack` lists the Lens script frames, one per line, in the same `at function (file:line:column)` shape browsers
* use, so it renders in DevTools and error reporters. File names refer to the scripts inside the Lens project, so
* they are most useful to the Lens creator.
*
* **Note:** No `LensScriptError` is created at all if the script `throw`s something other than an `Error` (a
* string, a number, a plain object). JavaScript only captures a stack when an `Error` is constructed, so a script
* that throws a bare value produces no frames — even though the script is what caused the failure.
*/
export type LensScriptError = NamedError<"LensScriptError">;
/** @internal */
export declare const lensScriptError: (message: string, cause?: unknown) => LensScriptError;
/**
* Returns the {@link LensScriptError} behind a Lens failure, or `undefined` if none was created. That happens
* when the failure wasn't the Lens's script (for example, the Lens could not be downloaded or one of its assets
* could not be loaded), or when the script threw something other than an `Error` — see {@link LensScriptError}.
*
* A Lens script can throw at two moments, and this works the same for both:
*
* ```ts
* import { findLensScriptError } from '@snap/camera-kit'
*
* // 1. While the Lens is being applied: applyLens rejects with a LensError.
* try {
* await cameraKitSession.applyLens(lens)
* } catch (error) {
* const scriptError = findLensScriptError(error)
* if (scriptError) console.log(`Lens ${lens.name} failed to start:\n${scriptError.stack}`)
* }
*
* // 2. While the Lens is rendering: Camera Kit removes the Lens and emits a LensExecutionError.
* cameraKitSession.events.addEventListener('error', ({ detail }) => {
* const scriptError = findLensScriptError(detail.error)
* if (scriptError) {
* console.log(`Lens ${detail.lens.name} has a script error:\n${scriptError.stack}`)
* } else {
* console.log(`Lens ${detail.lens.name} encountered an error and was removed.`)
* }
* })
* ```
*
* The stack looks like this:
*
* ```text
* LensScriptError: TypeError: cannot read property 'text' of undefined
* at onTap (Scripts/TapHandler.js:18:22)
* at apply (native)
* at (Scripts/TapHandler.js:9:5)
* ```
*
* @param error Any error emitted by Camera Kit. Values that are not an `Error` return `undefined`.
*/
export declare function findLensScriptError(error: unknown): LensScriptError | undefined;
/**
* This error occurs when a Lens attempts to play video, but the browser blocks audio playback due to autoplay policies.
* The video will still play, but in a muted state.
*
* Applications should handle this error by showing an unmute button or similar UI element,
* allowing the user to interact with the page and then unmute audio.
*
* ```ts
* cameraKitSession.events.addEventListener('error', ({ detail }) => {
* if (detail.error.name === 'LensVideoPlaybackMutedError') {
* // Show an unmute button that calls session.unmute() on user interaction
* unmuteButton.style.display = 'block'
* unmuteButton.onclick = () => {
* cameraKitSession.unmute()
* unmuteButton.style.display = 'none'
* }
* }
* })
* ```
*/
export type LensVideoPlaybackMutedError = NamedError<"LensVideoPlaybackMutedError">;
/** @internal */
export declare const lensVideoPlaybackMutedError: (message: string, cause?: unknown) => LensVideoPlaybackMutedError;
/**
* This error occurs when a session becomes inoperable.
*
* It's always a good idea to handle this error and update the user experience accordingly.
* For example, you could show a message to a user.
*
* ```ts
* cameraKitSession.events.addEventListener('error', ({ detail }) => {
* if (detail.error.name === 'LensAbortError') {
* console.log(`Camera Kit encountered an unrecoverable error and became inoperable. Please refresh the page.`)
* }
* })
* ```
*/
export type LensAbortError = NamedError<"LensAbortError">;
/** @internal */
export declare const lensAbortError: (message: string, cause?: unknown) => LensAbortError;
/**
* This error occurs when a Lens asked to persist data (for example, its settings), but Camera Kit failed to store it.
*/
export type PersistentStoreError = NamedError<"PersistentStoreError">;
/** @internal */
export declare const persistentStoreError: (message: string, cause?: unknown) => PersistentStoreError;
/**
* This error occurs when a Lens requested one of its assets, but Camera Kit failed to provide it.
*/
export type LensAssetError = NamedError<"LensAssetError">;
/** @internal */
export declare const lensAssetError: (message: string, cause?: unknown) => LensAssetError;
/**
* Thrown by {@link bootstrapCameraKit} if an error occurs during SDK initialization or while downloading the render
* engine WebAssembly.
*
* @category Bootstrapping and Configuration
*/
export type BootstrapError = NamedError<"BootstrapError">;
/** @internal */
export declare const bootstrapError: (message: string, cause?: unknown) => BootstrapError;
/**
* Thrown when a method receives an argument with an unexpected value.
*/
export type ArgumentValidationError = NamedError<"ArgumentValidationError">;
/** @internal */
export declare const argumentValidationError: (message: string, cause?: unknown) => ArgumentValidationError;
export {};
//# sourceMappingURL=namedErrors.d.ts.map