UNPKG

panicit

Version:

Exit or throw error immediately.

40 lines (38 loc) 1.15 kB
type PanicOption = { /** Note the cause of why the error is triggered. */ cause?: any; /** Should log panic message. */ silent?: boolean; /** Only works in Node.js env. */ exit?: boolean; /** Only works in Node.js env. */ exitCode?: number; }; /** * Define default config of panic function. */ type PanicConfig = Omit<PanicOption, 'cause'>; /** * Define global panicit config. * * ```ts * definePanicitConfig({exit: false, silent: false, exitCode: 1}); * ```` */ declare function definePanicitConfig(config: PanicConfig): void; /** * Terminates the program by throwing an error or exiting the process, and optionally logs a message and cause. * * ```ts * // Throwing a panic with a message * panic("Unexpected error occurred"); * * // Throwing a panic with a cause and custom exit behavior * panic("Database connection failed", {cause: "Timeout", exit: true, exitCode: 2}); * * // Silently throwing a panic * panic("Silent error", {silent: true}); * ``` */ declare function panic(message: any, opt?: PanicOption): never; export { type PanicConfig, type PanicOption, definePanicitConfig, panic };