Socket
Socket
Sign inDemoInstall

@thi.ng/errors

Package Overview
Dependencies
0
Maintainers
1
Versions
132
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @thi.ng/errors

Custom error types and error factory functions


Version published
Weekly downloads
207K
increased by3.37%
Maintainers
1
Install size
38.4 kB
Created
Weekly downloads
 

Readme

Source

@thi.ng/errors

npm version npm downloads Mastodon Follow

[!NOTE] This is one of 192 standalone projects, maintained as part of the @thi.ng/umbrella monorepo and anti-framework.

🚀 Please help me to work full-time on these projects by sponsoring me on GitHub. Thank you! ❤️

About

Custom error types and error factory functions.

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

Custom error types can be easily defined using defError().

Status

STABLE - used in production

Search or submit any issues for this package

Installation

yarn add @thi.ng/errors

ESM import:

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

Browser ESM import:

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

JSDelivr documentation

For Node.js REPL:

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

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

Dependencies

None

API

Generated API docs

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

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

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

License

© 2018 - 2024 Karsten Schmidt // Apache License 2.0

Keywords

FAQs

Last updated on 23 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc