npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

immutable-error

v0.1.5

Published

Generate errors for the Immutable App ecosystem

Downloads

7

Readme

immutable-error

Immutable Error provides harmonized error generator for modules in the Immutable App ecosystem.

Creating a new error generator instance

var immutableError = new ImmutableError({
    class: 'Foo',
    errorCodes: {
        100: 'foo error'
    },
    nameProperty: 'foo',
})

ImmutableError must be instantiated with an object containing the configuration options for the error generator.

The class property will be used as a prefix for all error messages.

The codes object defines a mapping of error codes to default error messages. Error codes must start at a number grater than 100 with a maximum length of three digits.

The nameProperty property will be used to get the name of the instance that the error occured with if both are set.

error

var error = immutableError.error(this, 100, 'foo error', err, {foo: true})

The error method generates and returns a new Error.

The arguments to error are:

  • instance - the instance (this) context that the error occurred in
  • code - the error code
  • message - a custom error message
  • error - the original Error object if re-throwing a caught error
  • data - any additional error data to include

All arguments are optional and an error will always be generated.

assert

immutableError.assert(foo === true, this, 100)

The assert method will evaluate its first argument and throw an error if it does not evaluate as truthy.

The subsequent arguments to assert will be passed to error to generate the Error.

Unlike error the assert method will throw the Error.

throw

immutableError.throw(this, 100)

The throw method calls error with the passed arguments and throws the generated error.

Generating an error without an instance

var error = immutableError.error(null, 100)

If an error is being generated outside of the context of a specific class instance then null should be passed as the first argument.

Generating an error without a code

var error = immutableError.error(this, null, 'foo')

If a code is not available for the error null or 0 should be used.

Generating an error with a custom error message

var error = immutableError.error(this, 100, 'custom error message')

A custom error can be passed as the third argument. If this argument is not a string it will not be used.

Generating an error from an existing error object

try {
    ...
} catch (err) {
    var error = immutableError.error(this, 100, null, err)
}

When catching and rethrowing an error pass the original error as the fourth argument and it will be added to the data of the error that is generated.

Error codes

The error codes defined by modules must be three digits starting with 100.

The error code will be used to lookup the default message for the error.

For registered classes the error code will be appended to a two digit prefix that identifies the class that generated the error.

If the class generating the error is not registered then the error code will always be 10000.

For classes that are registered where an error code is not specified the error code will be the class prefix followed by three zeros.

The three digit error code will always be stored in error.data.internalCode.

Registered classes

| base code | class | |-----------|------------------------------------------------------------------| | 20000 | ImmutableAppComponent |