Narcissistic Project Managers

    @thi.ng/errors
    TypeScript icon, indicating that this package has built-in type declarations

    2.1.6 • Public • Published

    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.

    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

    ES module import:

    <script type="module" src="https://cdn.skypack.dev/@thi.ng/errors"></script>

    Skypack documentation

    For Node.js REPL:

    # with flag only for < v16
    node --experimental-repl-await
    
    > const errors = await import("@thi.ng/errors");
    

    Package sizes (gzipped, pre-treeshake): ESM: 546 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 SNOWPACK_PUBLIC_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

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

    Install

    npm i @thi.ng/errors

    DownloadsWeekly Downloads

    43,777

    Version

    2.1.6

    License

    Apache-2.0

    Unpacked Size

    30.4 kB

    Total Files

    20

    Last publish

    Collaborators

    • thi.ng