/** * @typedef {object} MoyalErrorJSON * @property {string} name - The name of the error (usually the class name). * @property {string} message - The error message. * @property {string} timestamp - ISO 8601 timestamp of when the error was created. * @property {string | undefined} stack - The error's stack trace. * @property {MoyalErrorJSON | object | string | null} [cause] - The nested cause (recursively serialized if available). * @property {string} type - The actual class name (e.g., "MoyalError"). */ /** * Returns the semantic version of this library. * @returns {string} - The semantic version of this library. */ export function version(): string; /** * Builds a readable, indented summary of the cause chain. * * @param {Error} error - The error to trace. * @returns {string} A multiline string with each cause indented by depth. */ export function printCauseChain(error: Error): string; /** * Extends the native Javascript Error type to contain toJSON function. */ export function extendNativeError(): void; /** * Throws an {@link ArgumentError} if the given value is `null`. * * @param {*} value - The value to check. * @param {string} [argumentName] - The name of the argument being checked. * @throws {ArgumentError} */ export function throwIfNull(value: any, argumentName?: string): void; /** * Throws an {@link ArgumentError} if the given value is `undefined`. * * @param {*} value - The value to check. * @param {string} [argumentName] - The name of the argument being checked. * @throws {ArgumentError} */ export function throwIfUndefined(value: any, argumentName?: string): void; /** * Throws an {@link ArgumentError} if the given value is `null` or `undefined`. * * @param {*} value - The value to check. * @param {string} [argumentName] - The name of the argument being checked. * @throws {ArgumentError} */ export function throwIfNullOrUndefined(value: any, argumentName?: string): void; /** * Always throws an {@link ArgumentError} indicating a required argument is missing. * * @param {string} [argumentName] - The name of the missing argument. * @throws {ArgumentError} */ export function throwMissingArgument(argumentName?: string): void; /** * Throws an {@link ArgumentError} if the given value is an empty string. * * @param {*} value - The value to check. * @param {string} [argumentName] - The name of the argument being checked. * @throws {ArgumentError} */ export function throwIfEmptyString(value: any, argumentName?: string): void; /** * Throws an {@link ArgumentError} if the given value is `null`, `undefined`, * or a string that is empty or only whitespace. * * @param {*} value - The value to check. * @param {string} [argumentName] - The name of the argument being checked. * @throws {ArgumentError} */ export function throwIfNullOrWhitespace(value: any, argumentName?: string): void; /** * Custom error class with nested error support. * Automatically uses native `cause` if supported, otherwise simulates it. */ export class MoyalError extends Error { /** * Returns the version of this library. * * @returns {string} - The version of this library. */ static get version(): string; /** * @readonly * @type {boolean} */ static readonly "__#1@#_supportsNativeCause": boolean; /** * Tests if the current runtime supports native Error `cause` (ES2022). * @returns {boolean} */ static "__#1@#_testCauseSupport"(): boolean; /** * Indents all lines with a tab. * @param {string} str * @returns {string} */ static "__#1@#_tabify"(str: string): string; /** * Constructs a new MoyalError instance. * * @param {string} message - The error message. * @param {object|Error|string|null} [second] - Either an object with `{ cause }`, or a direct cause/error. */ constructor(message?: string, second?: object | Error | string | null); /** * Gets the cause of the error (native or simulated). * @returns {Error | undefined} */ get cause(): Error | undefined; /** * Serializes the error into a JSON-friendly object, including metadata for structured logging. * * @returns {MoyalErrorJSON} A plain object with name, message, stack, timestamp, and cause. */ toJSON(): MoyalErrorJSON; /** * Builds a full stack trace including all nested causes, recursively. * * @returns {string} A combined stack trace with each cause appended. */ get fullStack(): string; #private; } /** * Represents an error caused by invalid or missing function arguments. * Inherits from `MoyalError`. * * @extends {MoyalError} */ export class ArgumentError extends MoyalError { /** * Constructs a new ArgumentError. * * @param {string} message - The error message. * @param {string} [argumentName] - The name of the argument that caused the error. */ constructor(message: string, argumentName?: string); /** * Gets the name of the argument that caused the error. * * @returns {string|null} */ get argumentName(): string | null; #private; } export type MoyalErrorJSON = { /** * - The name of the error (usually the class name). */ name: string; /** * - The error message. */ message: string; /** * - ISO 8601 timestamp of when the error was created. */ timestamp: string; /** * - The error's stack trace. */ stack: string | undefined; /** * - The nested cause (recursively serialized if available). */ cause?: string | object | MoyalErrorJSON | null | undefined; /** * - The actual class name (e.g., "MoyalError"). */ type: string; };