# cli-handle-error

> Custom error handler for Node.js CLIs.

Latest version **4.4.2** (published 2026-05-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install cli-handle-error
pnpm add cli-handle-error
yarn add cli-handle-error
bun add cli-handle-error
```

## Health

**Score 45/100 (D)** — status: active.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 4.4.2 |
| Published | 2026-05-14 |
| First published | 2020-02-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Ahmad Awais |
| Maintainers | ahmadawais |
| Keywords | cli-handle-error, Ahmad Awais, ahmadawais |

## Links

- npm: https://www.npmjs.com/package/cli-handle-error
- Repository: https://github.com/ahmadawais/cli-handle-error
- Homepage: https://github.com/ahmadawais/cli-handle-error#readme
- Issues: https://github.com/ahmadawais/cli-handle-error/issues
- npm.io page: https://npm.io/package/cli-handle-error

## Dependencies (4)

- [chalk](https://npm.io/package/chalk.md) ^3.0.0
- [langbase](https://npm.io/package/langbase.md) *
- [log-symbols](https://npm.io/package/log-symbols.md) ^3.0.0
- [command-code](https://npm.io/package/command-code.md) *

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 4.4.2 (latest) — 2026-05-14
- 4.4.1 — 2025-01-27
- 4.4.0 — 2020-04-30
- 4.3.0 — 2020-04-30
- 4.2.0 — 2020-04-30
- 4.1.0 — 2020-03-24
- 4.0.0 — 2020-03-20
- 3.0.0 — 2020-03-20
- 2.2.1 — 2020-03-20
- 2.1.0 — 2020-03-20
- 2.0.0 — 2020-03-19
- 1.0.0 — 2020-02-15

## README

# cli-handle-error

[![DOWNLOADS](https://img.shields.io/npm/dt/node-cli-handle-error?label=DOWNLOADS%20%20❯&colorA=6A788D&colorB=6A788D&style=flat)](https://www.npmjs.com/package/node-cli-handle-error) [![Learn VSCode](https://img.shields.io/badge/-VSCODE.pro%20%E2%86%92-gray.svg?colorB=6A788D&style=flat)](https://VSCode.pro/?utm_source=GitHubFOSS)
[![Follow @MrAhmadAwais on Twitter](https://img.shields.io/badge/FOLLOW%20@MRAHMADAWAIS%20%E2%86%92-gray.svg?colorA=6A788D&colorB=6A788D&style=flat)](https://twitter.com/mrahmadawais/)

> Custom error handler for Node CLIs

<br>

[![📟](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/install.png)](./../../)

## Install

```sh
npm install node-cli-handle-error
```

<br>

[![⚙️](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/usage.png)](./../../)

## Usage

```js
const handleError = require('cli-handle-error');

// Let's say we get an error message from a custom command.
const [err, res] = await somePromise();

// Use the function. It will print the error and exit if there is an error.
handleError(`Failed while building on step #1`, err);
```

<br />

[![📃](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/options.png)](./../../)

## API

### handleError(heading, err, displayError?, exit?)

#### ❯ heading

Type: `string`<br>

Heading of the error message.

#### ❯ err

Type: `error/object`<br>

#### ❯ displayError

Type: `boolean`<br>
Default: `true` (optional)

Display the error message or not.

#### ❯ exit

Type: `boolean`<br>
Default: `true` (optional)

Exit the CLI on error or not?

<br>

[![📝](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/log.png)](changelog.md)

## Changelog

[❯ Read the changelog here →](changelog.md)

<br>

<small>**KEY**: `📦 NEW`, `👌 IMPROVE`, `🐛 FIX`, `📖 DOC`, `🚀 RELEASE`, and `✅ TEST`

> _I use [Emoji-log](https://github.com/ahmadawais/Emoji-Log), you should try it and simplify your git commits._

</small>

<br>

[![📃](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/license.png)](./../../)

## License & Conduct

- MIT © [Ahmad Awais](https://twitter.com/MrAhmadAwais/)
- [Code of Conduct](code-of-conduct.md)

<br>

[![🙌](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/connect.png)](./../../)

## Connect

<div align="left">
    <p><a href="https://github.com/ahmadawais"><img alt="GitHub @AhmadAwais" align="center" src="https://img.shields.io/badge/GITHUB-gray.svg?colorB=6cc644&colorA=6cc644&style=flat" /></a>&nbsp;<small><strong>(follow)</strong> To stay up to date on free & open-source software</small></p>
    <p><a href="https://twitter.com/MrAhmadAwais/"><img alt="Twitter @MrAhmadAwais" align="center" src="https://img.shields.io/badge/TWITTER-gray.svg?colorB=1da1f2&colorA=1da1f2&style=flat" /></a>&nbsp;<small><strong>(follow)</strong> To get #OneDevMinute daily hot tips & trolls</small></p>
    <p><a href="https://www.youtube.com/AhmadAwais"><img alt="YouTube AhmadAwais" align="center" src="https://img.shields.io/badge/YOUTUBE-gray.svg?colorB=ff0000&colorA=ff0000&style=flat" /></a>&nbsp;<small><strong>(subscribe)</strong> To tech talks & #OneDevMinute videos</small></p>
    <p><a href="https://AhmadAwais.com/"><img alt="Blog: AhmadAwais.com" align="center" src="https://img.shields.io/badge/MY%20BLOG-gray.svg?colorB=4D2AFF&colorA=4D2AFF&style=flat" /></a>&nbsp;<small><strong>(read)</strong> In-depth & long form technical articles</small></p>
    <p><a href="https://www.linkedin.com/in/MrAhmadAwais/"><img alt="LinkedIn @MrAhmadAwais" align="center" src="https://img.shields.io/badge/LINKEDIN-gray.svg?colorB=0077b5&colorA=0077b5&style=flat" /></a>&nbsp;<small><strong>(connect)</strong> On the LinkedIn profile y'all</small></p>
</div>

---
_Source: https://npm.io/package/cli-handle-error · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
