From 89ad16d320c8b661d85d140e73f379fe71eaf9a8 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Sun, 30 Oct 2022 17:55:42 +0100 Subject: [PATCH] Improve README --- README.md | 95 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 0517258..f740e74 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ + + + modern-errors logo + + [![Codecov](https://img.shields.io/codecov/c/github/ehmicky/modern-errors-cli.svg?label=tested&logo=codecov)](https://codecov.io/gh/ehmicky/modern-errors-cli) [![TypeScript](https://img.shields.io/badge/-typed-brightgreen?logo=typescript&colorA=gray&logoColor=0096ff)](/types/main.d.ts) [![Node](https://img.shields.io/node/v/modern-errors-cli.svg?logo=node.js&logoColor=66cc33)](https://www.npmjs.com/package/modern-errors-cli) @@ -8,6 +13,8 @@ [plugin](https://github.com/ehmicky/modern-errors#plugins-1) to handle errors in CLI modules. +This adds `error.exit()` which logs `error` then exits the process. + # Features - 🖍️ Pretty [colors](#%EF%B8%8F-colors), [icons](#-icon) and [header](#-header) @@ -84,50 +91,6 @@ This never throws. Invalid errors are silently _Type_: `object` -Options can apply to (in priority order): - -- Any error: second argument to - [`modernErrors()`](https://github.com/ehmicky/modern-errors#modernerrorsplugins-options) - -```js -export const AnyError = modernErrors(plugins, { cli: { ...options } }) -``` - -- Any error of multiple classes: using - [`ErrorClass.subclass()`](https://github.com/ehmicky/modern-errors#anyerrorsubclassname-options) - -```js -export const SharedError = AnyError.subclass('SharedError', { - cli: { ...options }, -}) - -export const InputError = SharedError.subclass('InputError') -export const AuthError = SharedError.subclass('AuthError') -``` - -- Any error of a specific class: second argument to - [`AnyError.subclass()`](https://github.com/ehmicky/modern-errors#anyerrorsubclassname-options) - -```js -export const InputError = AnyError.subclass('InputError', { - cli: { ...options }, -}) -``` - -- A specific error: second argument to the error's constructor - -```js -throw new InputError('...', { cli: { ...options } }) -``` - -- A specific - [`error.exit()`](https://github.com/ehmicky/modern-errors#errorexitoptions) - call - -```js -error.exit(...args, { ...options }) -``` - ### 🚨 exitCode _Type_: `integer` @@ -206,6 +169,50 @@ Special values: - `Number.POSITIVE_INFINITY`: Waits for ongoing tasks forever, without timing out +## Configuration + +[Options](#options) can apply to (in priority order): + +- Any error: second argument to + [`modernErrors()`](https://github.com/ehmicky/modern-errors#modernerrorsplugins-options) + +```js +export const AnyError = modernErrors(plugins, { cli: { ...options } }) +``` + +- Any error of multiple classes: using + [`ErrorClass.subclass()`](https://github.com/ehmicky/modern-errors#anyerrorsubclassname-options) + +```js +export const SharedError = AnyError.subclass('SharedError', { + cli: { ...options }, +}) + +export const InputError = SharedError.subclass('InputError') +export const AuthError = SharedError.subclass('AuthError') +``` + +- Any error of a specific class: second argument to + [`AnyError.subclass()`](https://github.com/ehmicky/modern-errors#anyerrorsubclassname-options) + +```js +export const InputError = AnyError.subclass('InputError', { + cli: { ...options }, +}) +``` + +- A specific error: second argument to the error's constructor + +```js +throw new InputError('...', { cli: { ...options } }) +``` + +- A specific [`error.exit()`](#errorexit) call + +```js +error.exit(...args, { ...options }) +``` + # Related projects # Support