Skip to content

Repository files navigation

logo-dark

🖨️ A Node.js Custom Error Library that print error stack without clutter.

NodeJSLicenseNPMCodecovCodacyCircleCI

English | 简体中文

Alt

preview.png

📖 Introduction

Inspired by the work of sindresorhus, I decided to open source the most repetitive encapsulation work I do in CLI development.

I do not like disorder. Often, unexpected situations arise due to our insufficient consideration. Therefore, I encourage those around me to engage in more comprehensive error collection work.

The goal of Exception is to transform unexpected occurrences into anticipated outcomes as much as possible.

It allows Error objects to throw exception and stack information in a more aesthetically pleasing and intuitive manner, and can also serve as Notify to output critical information in workflows.

inheritance-tree

⚙️ Installation

npm install @kabeep/exception --save
yarn add @kabeep/exception
pnpm add @kabeep/exception

🚀 Usage

Plain text or Error object

example

Plain-text-or-Error-object

importExceptionfrom'@kabeep/exception';// Plain textthrownewException('Argument example');// or Error objectthrownewException(newError('Argument example'));

Using in Asynchronous Contexts

example

Using-in-Asynchronous-Contexts

importExceptionfrom'@kabeep/exception';(async()=>{thrownewException('Promise example');})().catch(console.log);

Custom Styles

example

Custom-Styles

importExceptionfrom'@kabeep/exception';// Use custom style with hex or rgbconststylish='(51,51,51).bg#f56c6c';console.log(newException('Stylish example',stylish));

Custom Exceptions

example

Custom-Exceptions

importExceptionfrom'@kabeep/exception';// > WarningclassWarningextendsException{constructor(message: string|Error){super(message,'( 51 ,51, 51 ).bg#e6a23c');}}constwarn=newWarning('Inherited example');// Warning: Inherited example [Without style]console.log(`${warn}`);console.log(warn);

Print Key Information

example

Print-Key-Information

importExceptionfrom'@kabeep/exception';// > InfoconstinfoStyle='(51,51,51).bg#409eff';classInfoextendsException{constructor(message){super(message,infoStyle);}toString(){returnthis.info(styles);}}consttip=newInfo('Inherited example');// Without stackconsole.log(`${tip}`);// > SuccessconstsuccessStyle='(51,51,51).bg#67c23a';classSuccessextendsException{constructor(message){super(message,successStyle);}toString(){returnthis.info(styles);}}constpass=newSuccess('Inherited example');// Without stackconsole.log(pass.toString());

🎨 Supported styles

"dim.italic.underline"
"magenta.cyan"
"bgMagenta.bgCyan"
"#fff.bg#333333"
"(51,51,51).bg(24,124,255)"
"cyan.bgDarkblue"

🔗 Related

  • chalk - Terminal string styling done right
  • chalk-pipe - Create chalk style schemes with simpler style strings

🤝 Contribution

Contributions via Pull Requests or Issues are welcome.

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

About

🖨️ A Node.js Custom Error Library that print error stack without clutter.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages