# @blackglory/errors

> Common errors

Latest version **3.1.0** (published 2026-02-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @blackglory/errors
pnpm add @blackglory/errors
yarn add @blackglory/errors
bun add @blackglory/errors
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2026-02-17 |
| First published | 2020-12-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12 |
| Dependencies | 2 |
| Unpacked size | 21 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | BlackGlory |
| Maintainers | black_glory |

## Links

- npm: https://www.npmjs.com/package/@blackglory/errors
- Repository: https://github.com/BlackGlory/errors
- Homepage: https://github.com/BlackGlory/errors#readme
- Issues: https://github.com/BlackGlory/errors/issues
- npm.io page: https://npm.io/package/@blackglory/errors

## Dependencies (2)

- [extra-utils](https://npm.io/package/extra-utils.md) ^5.1.1
- [@blackglory/pass](https://npm.io/package/@blackglory/pass.md) ^1.1.0

## Recent versions

- 3.1.0 (latest) — 2026-02-17
- 3.0.3 — 2023-06-10
- 3.0.2 — 2023-04-05
- 3.0.1 — 2023-04-05
- 3.0.0 — 2023-01-22
- 2.4.3 — 2023-01-21
- 2.4.2 — 2023-01-21
- 2.4.1 — 2022-12-18
- 2.3.0 — 2022-11-07
- 2.2.3 — 2022-10-24
- 2.2.2 — 2022-08-01
- 2.2.1 — 2022-03-19
- 2.2.0 — 2022-02-10
- 2.1.0 — 2022-01-27
- 2.0.0 — 2022-01-11
- … 10 more at https://npm.io/package/@blackglory/errors/versions

## README

# errors
Common errors.

## Install
```sh
npm install --save @blackglory/errors
# or
yarn add @blackglory/errors
```

## API
```ts
type CustomErrorConstructor<T extends CustomError = CustomError> =
  new (message?: string) => T

interface SerializableError {
  name: string
  message: string
  stack: string | null
  ancestors: string[]
}
```

### CustomError
```ts
class CustomError extends Error {}
```

`CustomError` has better default behaviors than `Error`:
- `console.error` prints the correct exception name, not `Error`.
- `instanceof` operator matches based on names rather than inheritance relationships, which helps `SerializableError instanceof CustomError`.

### AssertionError
```ts
class AssertionError extends CustomError {}
```

### isError
```ts
function isError(val: unknown): val is Error
function isntError<T>(val: T): val is Exclude<T, Error>
```

### normalize
```ts
function normalize(err: Error): SerializableError
```

### hydrate
```ts
function hydrate(err: SerializableError): Error
```

### isSerializableError
```ts
function isSerializableError(val: unknown): val is SerializableError
```

### assert
```ts
/**
 * @throws {AssertionError}
 */
function assert(condition: unknown, message?: string): asserts condition
```

### getErrorNames
```ts
function getErrorNames(err: Error | SerializableError): Iterable<string>
```

### traverseErrorPrototypeChain
```ts
function traverseErrorPrototypeChain(err: Error): Iterable<Error>
```

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