Skip to content

Commit

Permalink
Improve README
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Oct 30, 2022
1 parent 56ea726 commit 89ad16d
Showing 1 changed file with 51 additions and 44 deletions.
95 changes: 51 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ehmicky/design/main/modern-errors/modern-errors_dark.svg"/>
<img alt="modern-errors logo" src="https://raw.githubusercontent.com/ehmicky/design/main/modern-errors/modern-errors.svg" width="600"/>
</picture>

[![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)
Expand All @@ -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)
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 89ad16d

Please sign in to comment.