handle-cli-error is a robust error handling library specifically designed for Node.js command-line interface (CLI) applications. It provides a comprehensive solution for displaying errors to users in a clear, consistent, and visually appealing manner, then gracefully exiting the process. The current stable version is 6.2.0, with frequent minor releases introducing new features and improvements, such as enhanced customization options. Key differentiators include its ability to generate pretty, colorized error output with icons and headers, support for error class-specific handling (allowing different exit codes or logging behaviors per error type), graceful process exit with customizable timeouts, and automatic normalization of invalid Error objects using `normalize-exception`. It also allows fine-grained control over what error details are logged, such as stack traces, nested error causes, and additional error properties, making it highly configurable for various CLI needs.
npm install handle-cli-errorVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of `handleCliError` within a try-catch block, including error class-specific options and custom configuration for output.
Ensure your project is configured for ESM, typically by setting `"type": "module"` in your `package.json` or by using `.mjs` file extensions. Replace all `require('handle-cli-error')` with `import handleCliError from 'handle-cli-error'`.Upgrade your Node.js runtime to version `18.18.0` or newer. If you are on an older Node.js version, you will need to stick to `handle-cli-error` v4.x.
If you previously relied on `props: false` to hide nested errors, you must now explicitly set `cause: false` instead. The `props` option now strictly controls additional error properties, not nested errors.
Always return a string from your `beautiful` method or the function specified by the `custom` option. For example: `class MyError extends Error { beautiful = (output) => `Customized: ${output}`; }`Migrate your file to ES modules by changing its extension to `.mjs` or by adding `"type": "module"` to your `package.json`. Then, use `import handleCliError from 'handle-cli-error'`.
First, ensure `npm install handle-cli-error` ran successfully. If your project is CommonJS, review the `ERR_REQUIRE_ESM` warning. Also, try deleting `node_modules` and `package-lock.json`, then reinstalling dependencies.
Ensure you are using the correct ESM default import: `import handleCliError from 'handle-cli-error'`. If using TypeScript, check your `tsconfig.json` for `"module": "Node16"` or `"NodeNext"` and `"esModuleInterop": true`.
The `props` option now controls only additional error properties, while `cause` controls nested errors (`error.cause` and `error.errors`). Set `cause: false` to hide nested errors, not `props: false`.
No dependency data recorded yet.