# @shieldsbetter/sberror2

> Javascript errors to my particular sensibilities.

Latest version **0.0.3** (published 2022-01-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install @shieldsbetter/sberror2
pnpm add @shieldsbetter/sberror2
yarn add @shieldsbetter/sberror2
bun add @shieldsbetter/sberror2
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2022-01-29 |
| First published | 2020-11-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 11.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Hampton Smith |
| Maintainers | shieldsbetter |
| Keywords | errors |

## Links

- npm: https://www.npmjs.com/package/@shieldsbetter/sberror2
- Repository: https://github.com/hamptonsmith/sberror2
- Homepage: https://github.com/hamptonsmith/sberror2#readme
- Issues: https://github.com/hamptonsmith/sberror2/issues
- npm.io page: https://npm.io/package/@shieldsbetter/sberror2

## Dependencies (3)

- [mustache](https://npm.io/package/mustache.md) ^4.0.1
- [camel-case](https://npm.io/package/camel-case.md) ^4.1.1
- [constant-case](https://npm.io/package/constant-case.md) ^3.0.3

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 0.0.3 (latest) — 2022-01-29
- 0.0.2 — 2021-12-23
- 0.0.1 — 2020-11-14

## README

# Shieldsbetter Errors

Javascript errors to my particular sensibilities.

## TL;DR

```javascript
const assert = require('assert');
const SbError = require('@shieldsbetter/sberrors2');

class OutOfCheeseError extends SbError {
	static messageTemplate = 'Cheese port {{port}} is out of {{cheeseType}}.';
}

const cause = new Error('Cheese delivery late.');

try {
	throw new OutOfCheeseError(cause, {
		port: 5,
		cheeseType: 'gouda',
		deployment: 'turkey sandwich'
	});
}
catch (e) {
	assert.equal(e.message, 'Cheese port 5 is out of gouda.');
	assert.equal(e.cause, cause);

	assert(e instanceof Error);
	assert(e instanceof SbError);
	assert(e instanceof OutOfCheeseError);

	assert.equal(e.code, 'OUT_OF_CHEESE_ERROR');
	assert(e.outOfCheeseError);
	assert(e.sbError);

	assert.deepEqual(e.details, {
		port: 5,
		cheeseType: 'gouda',
		deployment: 'turkey sandwich'
	});

	assert.equal(e.port, 5);
	assert.equal(e.cheeseType, 'gouda');
	assert.equal(e.deployment, 'turkey sandwich');
}
```

## Details

Static field `messageTemplate` will be rendered by the static method
`renderMessage`, which simply wraps
[Mustache](https://www.npmjs.com/package/mustache)`.render()` by default.

`renderMessage()` will be called with two arguments:

* The message template
* A details object (which could potentially be `undefined` but if defined is
  guaranteed to be an object)

Attempting to instantiate an error without a top-level `messageTemplate` will
yield an `SbError.CannotInstantiateAbstract` error.

Non-abstract error types may be instantiated with one or both of an
[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
cause and a details object, in any order.

---
_Source: https://npm.io/package/@shieldsbetter/sberror2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
