/** * @module @dotdo/postgres-shared/error-utils * * Lightweight error message extraction utilities. * Use these for simple error message handling without creating PostgresError objects. * * For full error handling with codes, context, and retryability, use the errors module. */ /** * Type guard to check if a value is an Error instance. * * @param value - The value to check * @returns True if the value is an Error instance * * @example * ```typescript * try { * await riskyOperation() * } catch (error) { * if (isError(error)) { * console.log(error.message) // TypeScript knows error is Error * console.log(error.stack) * } * } * ``` */ export declare function isError(value: unknown): value is Error; /** * Extract an error message from any value, including nested errors. * * Handles various error types consistently: * - Error instances: returns error.message (optionally includes nested cause) * - Strings: returns the string directly * - Objects with message property: returns the message as string * - Everything else: converts to string * * @param error - The value to extract a message from * @param options - Optional configuration * @param options.includeNested - Whether to include nested error causes (default: false) * @param options.maxDepth - Maximum depth for nested errors (default: 3) * @returns The extracted error message * * @example * ```typescript * try { * await riskyOperation() * } catch (error) { * // Simple extraction * console.log(extractErrorMessage(error)) * * // With nested errors * console.log(extractErrorMessage(error, { includeNested: true })) * // "Connection failed: DNS lookup failed: Network unreachable" * } * ``` */ export declare function extractErrorMessage(error: unknown, options?: { includeNested?: boolean; maxDepth?: number; }): string; /** * Extract an error message from any value. * * Handles various error types consistently: * - Error instances: returns error.message * - Strings: returns the string directly * - Objects with message property: returns the message as string * - Everything else: converts to string * * @example * ```typescript * try { * await riskyOperation() * } catch (error) { * console.log(formatError(error)) // Always returns a string * } * ``` */ export declare function formatError(error: unknown): string; /** * Wrap any value as an Error instance with optional context. * * Unlike the wrapError in errors.ts which creates PostgresError instances, * this creates plain Error objects for simpler use cases. * * @param error - The value to wrap * @param context - Optional context to prepend to the error message * @returns An Error instance * * @example * ```typescript * try { * await fetchData() * } catch (error) { * throw asError(error, 'Failed to fetch data') * // Error: "Failed to fetch data: Connection refused" * } * ``` */ export declare function asError(error: unknown, context?: string): Error; /** * Wrap any value as an Error instance with required context. * * This function is similar to asError but: * - Context is required (not optional) * - Preserves the original error as the cause for debugging * - Uses extractErrorMessage for better nested error handling * * @param error - The value to wrap * @param context - Context to prepend to the error message (required) * @returns An Error instance with the original error as cause * * @example * ```typescript * try { * await fetchData() * } catch (error) { * throw wrapError(error, 'Failed to fetch data') * // Error: "Failed to fetch data: Connection refused" * // with error.cause set to original error * } * ``` */ export declare function wrapError(error: unknown, context: string): Error; //# sourceMappingURL=error-utils.d.ts.map