Skip to content

Latest commit

 

History

History

errors

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

errors

npm version npm downloads Twitter Follow

This project is part of the @thi.ng/umbrella monorepo.

About

Custom error types and error factory functions.

Additional error types can be defined using defError().

Status

STABLE - used in production

Search or submit any issues for this package

Installation

yarn add @thi.ng/errors
// ES module
<script type="module" src="https://unpkg.com/@thi.ng/errors?module" crossorigin></script>

// UMD
<script src="https://unpkg.com/@thi.ng/errors/lib/index.umd.js" crossorigin></script>

Package sizes (gzipped, pre-treeshake): ESM: 356 bytes / CJS: 448 bytes / UMD: 508 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

Authors

Karsten Schmidt

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 - 2021 Karsten Schmidt // Apache Software License 2.0