modern-errors
Advanced tools
Comparing version 1.2.0 to 1.3.0
{ | ||
"name": "modern-errors", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"type": "module", | ||
@@ -55,5 +55,4 @@ "exports": "./build/src/main.js", | ||
"devDependencies": { | ||
"@ehmicky/dev-tasks": "^1.0.78", | ||
"test-each": "^5.0.0", | ||
"tsd": "^0.21.0" | ||
"@ehmicky/dev-tasks": "^1.0.84", | ||
"test-each": "^5.1.1" | ||
}, | ||
@@ -60,0 +59,0 @@ "engines": { |
@@ -1,2 +0,5 @@ | ||
<img src="https://raw.githubusercontent.com/ehmicky/design/main/modern-errors/modern-errors.svg" width="600"/> | ||
<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> | ||
@@ -31,2 +34,7 @@ [![Codecov](https://img.shields.io/codecov/c/github/ehmicky/modern-errors.svg?label=tested&logo=codecov)](https://codecov.io/gh/ehmicky/modern-errors) | ||
The framework integrates with [other libraries](#miscellaneous) to also: | ||
- Handle [CLI errors](#cli-errors) | ||
- Use [source maps](#source-maps) on stack traces | ||
# Example | ||
@@ -180,3 +188,3 @@ | ||
or that have | ||
[wrong/missing properties](https://github.com/ehmicky/normalize-exception#examples). | ||
[wrong/missing properties](https://github.com/ehmicky/normalize-exception#features). | ||
@@ -448,2 +456,31 @@ <!-- eslint-disable no-throw-literal --> | ||
### CLI errors | ||
CLI applications can assign a different exit code and log verbosity per error | ||
type by using [`handle-cli-error`](https://github.com/ehmicky/handle-cli-error). | ||
```js | ||
#!/usr/bin/env node | ||
import handleCliError from 'handle-cli-error' | ||
// `programmaticMain()` must use `modern-errors`'s `errorHandler` | ||
import programmaticMain from './main.js' | ||
const cliMain = function () { | ||
try { | ||
const cliFlags = getCliFlags() | ||
programmaticMain(cliFlags) | ||
} catch (error) { | ||
// Print `error` then exit the process | ||
handleCliError(error, { | ||
InputError: { exitCode: 1, short: true }, | ||
DatabaseError: { exitCode: 2, short: true }, | ||
default: { exitCode: 3 }, | ||
}) | ||
} | ||
} | ||
cliMain() | ||
``` | ||
### Source maps | ||
@@ -472,2 +509,4 @@ | ||
Polyfill `error.cause` | ||
- [`handle-cli-error`](https://github.com/ehmicky/handle-cli-error): 💥 Error | ||
handler for CLI applications | ||
@@ -474,0 +513,0 @@ # Support |
44220
2
536