import { BaseError } from "@xmachines/core/errors"; /** * The base class of every typed runtime error of a Play package. * * `PlayError` extends `BaseError` of `@xmachines/core/errors`, which gives each error two * structured fields: * - `scope` — the class or the module that threw the error, for example `"RouterBridgeBase"` * - `code` — a stable, machine-readable identifier, for example `"PLAY_ROUTER_SYNC_FAILED"` * * Your application code therefore branches on the type of an error, and it does not * parse the `.message` string. A message changes between releases. * * ## The error codes * * An `@xmachines/*` package that defines typed subclasses exports them from an * `"./errors"` subpath: * * | Package | Import | * | ------------------------------ | ----------------------------------------- | * | `@xmachines/play` | `@xmachines/play/errors` | * | `@xmachines/play-router` | `@xmachines/play-router/errors` | * | `@xmachines/play-url` | `@xmachines/play-url/errors` | * | `@xmachines/play-view` | `@xmachines/play-view/errors` | * | `@xmachines/play-vue-router` | `@xmachines/play-vue-router/errors` | * | `@xmachines/play-xstate` | `@xmachines/play-xstate/errors` | * * `PlayError` is the base of every subclass above, and it sits on the subpath with them. * The root barrel of `@xmachines/play` exports it never: one name has one import. A * package below the Play protocol, such as `@xmachines/core`, extends `BaseError` * directly, so `err instanceof BaseError` matches every typed error of the workspace. * * ## How to catch an error by its type * * ```typescript * import { PlayError } from "@xmachines/play/errors"; * import { RouterSyncError } from "@xmachines/play-router/errors"; * * try { * bridge.connect(); * } catch (err) { * if (err instanceof RouterSyncError) { * // err.scope === "RouterBridgeBase" * // err.code === "PLAY_ROUTER_SYNC_FAILED" * // err.cause — the original error of the failed synchronization * reportToMonitoring(err); * } else if (err instanceof PlayError) { * // Every other error of a Play package. `BaseError` of @xmachines/core/errors * // also matches an error of a package below the Play protocol. * console.error(`[${err.scope}:${err.code}] ${err.message}`); * } else { * throw err; // Throw an unknown error again * } * } * ``` * * ## How to extend PlayError * * ```typescript * import { PlayError } from "@xmachines/play/errors"; * * export class MyPackageError extends PlayError { * constructor(message: string, options?: ErrorOptions) { * super("MyScope", "MY_PACKAGE_ERROR_CODE", message, options); * this.name = "MyPackageError"; * } * } * ``` */ export declare class PlayError extends BaseError { /** * @param scope - The class or the module that throws this error. * @param code - The machine-readable identifier of the error, for example `"PLAY_ROUTER_SYNC_FAILED"`. * A Play package names a code `PLAY__`. * @param message - The description for a person. Never match on it in your code. * @param options - The standard `ErrorOptions`. Give `{ cause: originalError }` to make a chain of errors. */ constructor(scope: string, code: string, message: string, options?: ErrorOptions); } /** * {@link @xmachines/play!index.assertNonNullable} throws this error when a value is `null` or `undefined`. * * Catch it to separate a failed assertion of a missing value from every other * runtime error: * * ```ts * import { NonNullableError } from "@xmachines/play/errors"; * * try { * const actor = assertNonNullable(inject("actor"), "actor"); * } catch (err) { * if (err instanceof NonNullableError) { * // err.name === "NonNullableError" * // err.scope === "assertNonNullable" * // err.code === "PLAY_NON_NULLABLE" * } * } * ``` */ export declare class NonNullableError extends PlayError { constructor(message: string, options?: ErrorOptions); } //# sourceMappingURL=errors.d.ts.map