Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a1ecac2
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": {} | ||
} |