💣 Error handler for CLI applications 💥

Overview
handle-cli-error logo

Codecov Node TypeScript Twitter Medium

Error handler for CLI applications.

Features

Example

General

#!/usr/bin/env node
import handleCliError from 'handle-cli-error'

const cliMain = function () {
  try {
    // ...
  } catch (error) {
    handleCliError(error) // Print `error` then exit the process
  }
}

cliMain()

Error type-specific

handleCliError(error, {
  types: {
    InputError: { exitCode: 1, short: true },
    DatabaseError: { exitCode: 2, short: true },
    InternalError: { exitCode: 3 },
  },
})

Install

npm install handle-cli-error

This package is an ES module and must be loaded using an import or import() statement, not require().

API

handleCliError(error, options?)

error any
options Options?
Return value: undefined

Prints error on the console (stderr) then exits the process.

This never throws. Invalid errors are silently normalized.

Options

🚨 exitCode

Type: integer
Default: 1

Process exit code.

Note: when passing invalid options, the exit code is always 125.

📕 short

Type: boolean
Default: false

When true, only the error message is logged, not its stack trace.

This is useful when the error was caused by the user (as opposed to being an internal bug), in which cause the stack trace is not relevant to the user.

🔕 silent

Type: boolean
Default: false

When true, the error is not logged. The process still exits with a specific exit code.

🚒 timeout

Type: integer (in milliseconds)
Default: 5000 (5 seconds)

The process exits gracefully: it waits for any ongoing tasks (callbacks, promises, etc.) to complete, up to a specific timeout.

Special values:

  • 0: Exits right away, without waiting for ongoing tasks
  • Number.POSITIVE_INFINITY: Waits for ongoing tasks forever, without timing out

💣 types

Type: object
Default: {}

Specify different options per error type. The object:

  • Keys are either the error.name, or "default" (used if no error.name matches)
  • Values are options objects

Related projects

Credits

The logo background was created by dgim-studio.

Support

For any question, don't hesitate to submit an issue on GitHub.

Everyone is welcome regardless of personal background. We enforce a Code of conduct in order to promote a positive and inclusive environment.

Contributing

This project was made with ❤️ . The simplest way to give back is by starring and sharing it online.

If the documentation is unclear or has a typo, please click on the page's Edit button (pencil icon) and suggest a correction.

If you would like to help us fix a bug or add a new feature, please check our guidelines. Pull requests are welcome!

You might also like...

1kb js library contains development debugging, error monitoring and reporting, user problem localization features

1kb js library contains development debugging, error monitoring and reporting, user problem localization features

1kb js library contains development debugging, error monitoring and reporting, user problem localization features

Dec 22, 2022

Webpack dev tools to make performance analysis, error investigation and loader development more convenient

Webpack dev tools to make performance analysis, error investigation and loader development more convenient

build-tool-inspector Introduction Webpack dev tools to make performance analysis, error investigation and loader development more convenient. Provide

Nov 17, 2022

VS Code extension that adds a red error squiggle to every word in your code.

VS Code extension that adds a red error squiggle to every word in your code.

Dumbisense Dumbisense is a VS Code extension that adds a red error squiggle to every word in your code, with an interesting error message and dino ima

Sep 3, 2022

An Amazing SlashCommands Handler (With Sharding & Mongo) Made by discord.gg/azury

An Amazing SlashCommands Handler (With Sharding & Mongo) Made by discord.gg/azury

SlashCommands Handler by The Azury Team If this Git-Repo gets "40" Stars ⭐ i'll add some more Commands! 🛠️ FEATURES: 1. SlashCommands Support 2. Cont

Dec 2, 2022

🤖 Makes it easy to create bots on discord through a simple command handler

🤖 Makes it easy to create bots on discord through a simple command handler

MyBotHelper.JS 📚 About facilitates the creation of bots via discord.js, the repository already has a main script that automatically synchronizes and

Dec 31, 2022

A Discord.JS Command Handler to handle commands eaiser

TABLE OF CONTENTS Installation Setup Changing Default Prefix Creating a Command Usage of minArgs and maxArgs Syntax Errors Global Syntax Errors Per Co

Jun 8, 2022

New Discord.JS v14 Slash and Prefix Commands handler with Events. Check it out now!

New Discord.JS v14 Slash and Prefix Commands handler with Events. Check it out now!

Discord.js v14 Command-Handler Commands, Events, Permissions and Cooldown Handlers for Discord.js v14 bot ~ Made by Lynx Discord.js v14 (dev version)

Dec 19, 2022

Provides a KafkaJS-compatible handler for processing messages that facilitates publishing to delayed-retry or dead-letter topics

kafkajs-async-retry This module handles retries and dead-lettering for messages from a Kafka topic without blocking the processing of subsequent messa

Dec 5, 2022

A Discord bot Template made with Discord.JS version 14 includes Prefix, Slash commands and MongoDB handler.

A Discord bot Template made with Discord.JS version 14 includes Prefix, Slash commands and MongoDB handler.

Project Language: Fork/Download for: Project Requirements: Database Available: DiscordJS V14 Bot Template - Introduction: A Discord bot project made w

Jan 3, 2023
Comments
  • Bump decode-uri-component from 0.2.0 to 0.2.2

    Bump decode-uri-component from 0.2.0 to 0.2.2

    Bumps decode-uri-component from 0.2.0 to 0.2.2.

    Release notes

    Sourced from decode-uri-component's releases.

    v0.2.2

    • Prevent overwriting previously decoded tokens 980e0bf

    https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.1...v0.2.2

    v0.2.1

    • Switch to GitHub workflows 76abc93
    • Fix issue where decode throws - fixes #6 746ca5d
    • Update license (#1) 486d7e2
    • Tidelift tasks a650457
    • Meta tweaks 66e1c28

    https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.1

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Releases(3.1.1)
Owner
ehmicky
Node.js back-end developer
ehmicky
Error and Success Handler for Passport.js

passport-handler Developed with ❤️ by Swôth ?? Installation npm i passport-handler --save yarn add passport-handler ?? Importing import Handler from '

Swôth 2 Oct 29, 2022
DiscordJs13-handler is the solution for all the discord.js developper who want a complete handler for slash commands

DiscordJs13-handler is the solution for all the discord.js developper who want a complete handler for slash commands

null 9 Jul 2, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Node-cli-starter - Basic starter kit for building Node CLI applications with TypeScript.

node-cli-starter Minimal starter kit for building Node CLI applications with TypeScript. Getting Started To get started clone repo locally and run npm

Cory Rylan 7 May 17, 2022
Unstyled, dev error overlays for SolidJS

solid-error-overlay Unstyled, headless Error Overlay for SolidJS Install npm i solid-error-overlay yarn add solid-error-overlay pnpm add solid-error-o

Alexis H. Munsayac 20 Dec 29, 2022
A Little explanation of the famous Javascript parseInt(0.0000005); error meme.

Explaining the meme Internet is made of millions of memes flowing everyday, so, devs create a ton of new images showing how their code doesn't work, t

akrck02 2 Feb 3, 2022
Colorconsole provides an interesting way to display colored info, success, warning and error messages on the developer console in your browser

ColorConsole NPM Package Colorconsole provides an interesting way to display colored info, success, warning and error messages on the developer consol

Hasin Hayder 17 Sep 19, 2022
Polyfill `error.cause`

Polyfill error.cause. error.cause is a recent JavaScript feature to wrap errors. try { doSomething() } catch (cause) { throw new Error('message',

ehmicky 4 Dec 15, 2022