|
| 1 | +# [](https://discord.gg/M6aTR9eTwN) |
| 2 | + |
| 3 | +## @eliware/errors [](https://www.npmjs.com/package/@eliware/errors)[](LICENSE)[](https://github.com/eliware/errors/actions) |
| 4 | + |
| 5 | +> Minimal Node.js process-level error handler utility for uncaught exceptions, unhandled rejections, and warnings. Works in both CommonJS and ESM environments. |
| 6 | +
|
| 7 | +--- |
| 8 | + |
| 9 | +## Table of Contents |
| 10 | + |
| 11 | +- [Features](#features) |
| 12 | +- [Installation](#installation) |
| 13 | +- [Usage](#usage) |
| 14 | + - [ESM Example](#esm-example) |
| 15 | + - [CommonJS Example](#commonjs-example) |
| 16 | +- [API](#api) |
| 17 | +- [TypeScript](#typescript) |
| 18 | +- [Support](#support) |
| 19 | +- [License](#license) |
| 20 | +- [Links](#links) |
| 21 | + |
| 22 | +## Features |
| 23 | + |
| 24 | +- Handles uncaught exceptions, unhandled rejections, and warnings |
| 25 | +- Pluggable logger (defaults to [@eliware/log](https://www.npmjs.com/package/@eliware/log)) |
| 26 | +- Easy to add/remove handlers for testability |
| 27 | +- Works in both CommonJS and ESM modules |
| 28 | + |
| 29 | +## Installation |
| 30 | + |
| 31 | +```bash |
| 32 | +npm install @eliware/errors |
| 33 | +``` |
| 34 | + |
| 35 | +## Usage |
| 36 | + |
| 37 | +### ESM Example |
| 38 | + |
| 39 | +```js |
| 40 | +import { registerHandlers } from '@eliware/errors'; |
| 41 | +registerHandlers(); |
| 42 | + |
| 43 | +// Or with options: |
| 44 | +// registerHandlers({ processObj: process, log: customLogger }); |
| 45 | + |
| 46 | +// Simulate an uncaught exception |
| 47 | +setTimeout(() => { throw new Error('Demo uncaught exception'); }, 1000); |
| 48 | +``` |
| 49 | + |
| 50 | +### CommonJS Example |
| 51 | + |
| 52 | +```js |
| 53 | +const { registerHandlers } = require('@eliware/errors'); |
| 54 | +registerHandlers(); |
| 55 | + |
| 56 | +// Or with options: |
| 57 | +// registerHandlers({ processObj: process, log: customLogger }); |
| 58 | + |
| 59 | +// Simulate an uncaught exception |
| 60 | +setTimeout(() => { throw new Error('Demo uncaught exception'); }, 1000); |
| 61 | +``` |
| 62 | + |
| 63 | +## API |
| 64 | + |
| 65 | +### registerHandlers(options) |
| 66 | + |
| 67 | +Registers process-level exception handlers. Returns an object with a `removeHandlers` function to detach all handlers (useful for testing). |
| 68 | + |
| 69 | +- `options` (optional): An object with the following properties: |
| 70 | + - `processObj` (optional): The process object to attach handlers to (default: `process`) |
| 71 | + - `log` (optional): Logger for output (default: [@eliware/log](https://www.npmjs.com/package/@eliware/log)) |
| 72 | +- **Returns:** `{ removeHandlers: () => void }` |
| 73 | + |
| 74 | +## TypeScript |
| 75 | + |
| 76 | +Type definitions are included: |
| 77 | + |
| 78 | +```ts |
| 79 | +export declare function registerHandlers( |
| 80 | + options?: { |
| 81 | + processObj?: NodeJS.Process, |
| 82 | + log?: typeof import('@eliware/log') |
| 83 | + } |
| 84 | +): { removeHandlers: () => void }; |
| 85 | +``` |
| 86 | + |
| 87 | +## Support |
| 88 | + |
| 89 | +For help, questions, or to chat with the author and community, visit: |
| 90 | + |
| 91 | +[](https://discord.gg/M6aTR9eTwN)[](https://discord.gg/M6aTR9eTwN) |
| 92 | + |
| 93 | +**[eliware.org on Discord](https://discord.gg/M6aTR9eTwN)** |
| 94 | + |
| 95 | +## License |
| 96 | + |
| 97 | +[MIT © 2025 Eli Sterling, eliware.org](LICENSE) |
| 98 | + |
| 99 | +## Links |
| 100 | + |
| 101 | +- [Home Page](https://eliware.org) |
| 102 | +- [GitHub](https://github.com/eliware/errors) |
| 103 | +- [npm](https://www.npmjs.com/package/@eliware/errors) |
| 104 | +- [Discord](https://discord.gg/M6aTR9eTwN) |
0 commit comments