Skip to content

Commit

Permalink
* First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
joehewitt committed Jul 9, 2011
0 parents commit a1ecac2
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
20 changes: 20 additions & 0 deletions dandy.js
@@ -0,0 +1,20 @@

/**
* Shorthand for console.log
*
* Best way to use is to write D&&D("message")
* In production, just set the global variable D to null. This allows you to leave in debug
* statements, but limit their cost to the boolean test of the D variable.
*/
function D() {
console.log.apply(console, arguments);
}

try {
// Node.js version
global.D = D;
Error.stackTraceLimit = 1000;
} catch (exc) {
// Browser version
window.D = D;
}
34 changes: 34 additions & 0 deletions errors.js
@@ -0,0 +1,34 @@

require('./dandy');

/**
* Asynchronous bind
*
* Automatically passes errors and exceptions to the callback.
*/
exports.abind = function(fn, cb, self) {
return function(err, result) {
if (err) { if (cb) cb(err); return; }

try {
fn.apply(self, arguments);
} catch (exc) {
exports.logException(exc);
if (cb) cb(exc);
}
}
}

/**
* Logs exceptions to stderr in a friendly way.
*/
exports.logException = function(exc, detail) {
var util = require('util');

if (detail) {
util.debug(detail);
}
if (exc.stack) {
util.debug(exc.stack);
}
};
14 changes: 14 additions & 0 deletions package.json
@@ -0,0 +1,14 @@
{
"name": "dandy",
"description": "Error handling and logging utilities",
"version": "0.0.1",
"url": "http://github.com/joehewitt/dandy",
"keywords": [],
"author": "Joe Hewitt <joe@joehewitt.com>",
"contributors": [],
"dependencies": {
},
"engines": { "node": ">=0.4.0" },
"main": "./dandy",
"directories": {}
}

0 comments on commit a1ecac2

Please sign in to comment.