Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/presentable-error
Make presentable errors
https://github.com/sindresorhus/presentable-error
Last synced: about 1 month ago
JSON representation
Make presentable errors
- Host: GitHub
- URL: https://github.com/sindresorhus/presentable-error
- Owner: sindresorhus
- License: mit
- Created: 2023-08-25T00:52:47.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-25T10:15:57.000Z (about 1 year ago)
- Last Synced: 2024-04-14T11:09:15.649Z (7 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 60
- Watchers: 7
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# presentable-error
> Make presentable errors
**Work in progress. Request for feedback.**
The idea is to create a convention for errors that are meant to be presented to the user without a stack trace. Same as any object with a `.then` property can be awaited (duck-typing), I would like to create a convention where every error with a `.isPresentable` property should be presented to the user in a nicer way. This is especially useful for command-line tools. For example, if a command-line tool uses packages that follow the presentable error convention, the command-line tool could simply check for `error.isPresentable` and then log it nicely instead of throwing such errors.
This package comes with types for creating presentable errors and checking for them, but if you follow the convention, you don't even need to use this package directly. This can be useful if you want to use your own error subclasses. Then you can simply add the `.isPresentable` property. Ensure it's non-writable and non-configurable.
## Install
```sh
npm install presentable-error
```## Usage
See [`index.d.ts`](index.d.ts) for now.
#### Example in CLI
```js
import meow from 'meow';try {
throwableFunction();
} catch (error) {
if (error.isPresentable) {
console.error(error.message);
process.exit(1);
}throw error;
}
```