{{pkg.description}}
This package defines the following error types & helper functions to throw them:
AssertionError
IllegalArgumentError
IllegalArityError
IllegalStateError
OutOfBoundsError
UnsupportedOperationError
Custom error types can be easily defined using
defError()
.
{{meta.status}}
{{repo.supportPackages}}
{{repo.relatedPackages}}
{{meta.blogPosts}}
{{pkg.install}}
{{pkg.size}}
{{pkg.deps}}
{{repo.examples}}
{{pkg.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
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"
.