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

ezone

v0.20.1

Published

ErrorZone - Javascript Error Framework

Downloads

5

Readme

ErrorZone - Javascript Error Framework

Build Status

The ErrorZone framework helps to use error stack data more efficiently.

Installation

npm install ezone
bower install e3

Environment compatibility

This framework supports the same environments as the error polyfill lib.

I used Karma with Browserify to test the framework in browsers and I used Yadda to run the BDD tests.

Requirements

The error polyfill and the o3 libs are required.

Usage

In this documentation I used the framework as follows:

var e3 = require("ezone"),
    UserError = e3.UserError,
    CompositeError = e3.CompositeError,
    Stack = e3.Stack,
    CompositeStack = e3.CompositeStack;

Errors

Creating custom errors

You can create custom Error sub-classes by extending the UserError class.

var MyError = UserError.extend({
    prototype: {
        name: "MyError"
    }
});

try {
    throw new MyError("problem");
}
catch (theProblem) {
    if (!(theProblem instanceof MyError))
        throw theProblem;
    console.log(theProblem);
        // MyError: problem
    console.log(Error.getStackTrace(theProblem).toString());
        // MyError: problem
            // at (example.js:2:16)
            // at ...
            // ...
}

Overriding and reusing the constructor and the clone method is not recommended by descendant classes, use build and init instead!

Creating composite errors

You can create composite errors with the CompositeError class if you want to report complex problems, which can only described by a hierarchy of error objects.

var MyCompositeError = CompositeError.extend({
    prototype: {
        name: "MyCompositeError"
    }
});

try {
    try {
        throw new MyError("problem");
    }
    catch (theProblem) {
        throw new MyCompositeError({
            message: "complex problem",
            theSource: theProblem
        })
    }
}
catch (theComplexProblem) {
    console.log(Error.getStackTrace(theComplexProblem).toString());
        // MyCompositeError: complex problem
            // at (example.js:5:32)
            // at ...
            // ...
        // caused by <theSource> MyError: problem
            // at (example.js:2:16)
            // at ...
            // ...
}

The CompositeError can be a great help for example by nested validation errors or by reporting about multiple parallel async failures.

Accessing stack frames

If you have your Stack instance, you can access the frames array by reading the stack.frames property.

var stack = Error.getStackTrace(error);
var frames = stack.frames;
for (var index in frames) {
    var frame = frames[index];
    console.log(frame.toString()); // e.g. "fn (example.js:1:1)"
    console.log(frame.getFunction()); // e.g. function fn(){}
}

Using the stack as a string

People tend to use the error.stack as it were a string. This is usually not a wrong assumption, so I added this feature to the lib.

var error = new UserError("cause");
var lines = error.stack.split("\n");
for (var i in lines)
    console.log(line[i]);

This should work despite the fact that the error.stack contains a Stack instance by UserError.

License

MIT - 2015 Jánszky László Lajos