# @thi.ng/errors

> Custom error types and error factory functions

Latest version **2.6.17** (published 2026-08-25) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @thi.ng/errors
pnpm add @thi.ng/errors
yarn add @thi.ng/errors
bun add @thi.ng/errors
```

## Health

**Score 70/100 (B)** — status: active.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.6.17 |
| Published | 2026-08-25 |
| First published | 2018-05-10 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 32.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Karsten Schmidt |
| Maintainers | thi.ng |
| Keywords | assert, errors, typescript |

## Links

- npm: https://www.npmjs.com/package/@thi.ng/errors
- Repository: https://codeberg.org/thi.ng/umbrella
- Homepage: https://thi.ng/errors
- Funding: https://github.com/sponsors/postspectacular
- npm.io page: https://npm.io/package/@thi.ng/errors

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 2.6.17 (latest) — 2026-08-25
- 2.6.16 — 2026-07-02
- 2.6.15 — 2026-06-05
- 2.6.14 — 2026-05-23
- 2.6.13 — 2026-05-20
- 2.6.11 — 2026-05-11
- 2.6.10 — 2026-05-08
- 2.6.9 — 2026-04-26
- 2.6.8 — 2026-04-18
- 2.6.7 — 2026-04-02
- 2.6.6 — 2026-03-19
- 2.6.5 — 2026-03-07
- 2.6.4 — 2026-03-07
- 2.6.3 — 2026-02-07
- 2.6.2 — 2026-01-23
- … 176 more at https://npm.io/package/@thi.ng/errors/versions

## README

<!-- This file is generated - DO NOT EDIT! -->
<!-- Please see: https://codeberg.org/thi.ng/umbrella/src/branch/develop/CONTRIBUTING.md#changes-to-readme-files -->
# ![@thi.ng/errors](https://codeberg.org/thi.ng/umbrella/media/branch/develop/assets/banners/thing-errors.svg?d7513125)

[![npm version](https://img.shields.io/npm/v/@thi.ng/errors.svg)](https://www.npmjs.com/package/@thi.ng/errors)
![npm downloads](https://img.shields.io/npm/dm/@thi.ng/errors.svg)
[![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)

> [!NOTE]

> This is one of 217 standalone projects. LLM-free, human-made and
> cared for software, maintained as part of the
> [@thi.ng/umbrella](https://codeberg.org/thi.ng/umbrella/) ecosystem and
> anti-framework.
>
> 🚀 Please help me to work full-time on these projects by [sponsoring
> me](https://codeberg.org/thi.ng/umbrella/src/branch/develop/CONTRIBUTING.md#donations).
> Thank you! ❤️

- [About](#about)
- [Status](#status)
- [Installation](#installation)
- [Dependencies](#dependencies)
- [Usage examples](#usage-examples)
- [API](#api)
  - [Environment variables](#environment-variables)
- [Authors](#authors)
- [License](#license)

## About

Custom error types and error factory functions.

This package defines the following error types & helper functions to throw them:

- [`AssertionError`](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/errors/src/assert.ts)
- [`IllegalArgumentError`](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/errors/src/illegal-arguments.ts)
- [`IllegalArityError`](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/errors/src/illegal-arity.ts)
- [`IllegalStateError`](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/errors/src/illegal-statre.ts)
- [`OutOfBoundsError`](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/errors/src/out-of-bounds.ts)
- [`UnsupportedOperationError`](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/errors/src/unsupported.ts)

Custom error types can be easily defined using
[`defError()`](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/errors/src/deferror.ts).

## Status

**STABLE** - used in production

[Search or submit any issues for this package](https://codeberg.org/thi.ng/umbrella/issues?q=%5Berrors%5D)

## Installation

```bash
yarn add @thi.ng/errors
```

ESM import:

```ts
import * as err from "@thi.ng/errors";
```

Browser ESM import:

```html
<script type="module" src="https://esm.run/@thi.ng/errors"></script>
```

[JSDelivr documentation](https://www.jsdelivr.com/)

For Node.js REPL:

```js
const err = await import("@thi.ng/errors");
```

Package sizes (brotli'd, pre-treeshake): ESM: 849 bytes

## Dependencies

None

## Usage examples

One project in this repo's
[/examples](https://codeberg.org/thi.ng/umbrella/src/branch/develop/examples)
directory is using this package:

| Description                                                                  | Live demo                                          | Source                                                                                  |
|:-----------------------------------------------------------------------------|:---------------------------------------------------|:----------------------------------------------------------------------------------------|
| GPU-based data reduction using thi.ng/shader-ast & WebGL multi-pass pipeline | [Demo](https://demo.thi.ng/umbrella/gpgpu-reduce/) | [Source](https://codeberg.org/thi.ng/umbrella/src/branch/develop/examples/gpgpu-reduce) |

## API

[Generated API docs](https://docs.thi.ng/umbrella/errors/)

```ts
import * as err from "@thi.ng/errors";

err.illegalArity(3)
// Error: illegal arity: 3

err.illegalArgs("expected foo");
// Error: illegal argument(s): expected foo

err.illegalState("oops");
// Error: illegal state: oops

err.unsupported("TODO not yet implemented")
// Error: unsupported operation: TODO not yet implemented

// define custom error
const MyError = err.defError(
    () => "Eeek... ",
    (x) => x + " is not allowed!"
);

try {
    throw new MyError(23);
} catch(e) {
    console.warn(e.message);
    console.log(e instanceof Error);
}
// Eeek... 23 is not allowed!
// true
```

### Environment variables

The `UMBRELLA_ASSERTS` or `VITE_UMBRELLA_ASSERTS` env variables are
used to control the behavior of the `assert()` function in production builds: If
either is set (to a non-empty string), the function will **always** be enabled.
Otherwise (by default), `assert()` will be **disabled for production builds**,
i.e. if `process.env.NODE_ENV === "production"`.

## Authors

- [Karsten Schmidt](https://thi.ng)

If this project contributes to an academic publication, please cite it as:

```bibtex
@misc{thing-errors,
  title = "@thi.ng/errors",
  author = "Karsten Schmidt",
  note = "https://thi.ng/errors",
  year = 2018
}
```

## License

&copy; 2018 - 2026 Karsten Schmidt // Apache License 2.0

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