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 🙏

© 2025 – Pkg Stats / Ryan Hefner

prettified

v0.0.7

Published

Prettified error handling for Node.js

Readme

Prettified error handling for Node.js

Installing

npm install prettified

Pretty printing exceptions

This sample code:

var errors = require('prettified').errors;
try {
	throw new Error("Example error");
} catch(err) {
	errors.print(err);
}

...will print errors using console.error() like this:

/---------------------------------- Error -----------------------------------\
| Error: Example error
+---------------------------------- stack -----------------------------------+
|     at Object.<anonymous> (/home/jhh/git/node-prettified/examples/format.js:3:8)
|     at Module._compile (module.js:449:26)
|     at Object.Module._extensions..js (module.js:467:10)
|     at Module.load (module.js:356:32)
|     at Function.Module._load (module.js:312:12)
|     at Module.runMain (module.js:492:10)
|     at process.startup.processNextTick.process._tickCallback (node.js:244:9)
\----------------------------------------------------------------------------/

Catch errors inside callbacks

The errors.catchfail([opts, ]callback) is a wrapper builder to catch exceptions inside function call.

It returns a function which when invoked calls the callback and passes all original arguments and returns the value untouched.

If exceptions are thrown it will catch them and print them using console.error() or by using a handler specified in opts. Handlers can be functions or Promise A defers (see the q library).

Example 1

You can simply wrap your existing callback handlers with catchfail like this:

require('fs').exists('test.txt', errors.catchfail(function(exists) {
	console.log('test.txt ' + (exists ? 'exists' : 'not found') );
}));

Example 2 -- with an error handler

If you like to handle the error you can pass an error handler as a first argument:

function do_error(err) {
	errors.print(err);
}
setTimeout(errors.catchfail(do_error, function() {
	throw new TypeError("Example error");
}), 200);

Example 3 -- with defers as an error handler

You can also use defers from the q library as an error handler:

function test() {
	var defer = require('q').defer();
	setTimeout(errors.catchfail(defer, function() {
		throw new TypeError("Example error");
	}), 200);
	return defer.promise;
}

test().fail(function(err) {
	errors.print(err);
});

Setting default error type

You can set default error type for uncatched errors like this:

errors.setDefaultError(MySystemError);