errup - magic error handling for node.js
All hates "callback hell" in node.js. With this module you doesn't need check 'err' every callback. Callback error will be checked automaticly and will be rised if it needed.
Old style(without errup)
{ fs;}
New style - with errup (JavaScript)
errUp = ; { fs;} // express sampleapp;
With CoffeeScript
errUp = require 'errup'appget "/" readDirectoryAsync __dirnameerrUp ressend filenames
Can also set error handler callback
May be need if last function in stack is not errUp(eg closure, or other)
appget "/" do anyAsyncFunc errUp next ressend ret = fsreaddir __dirname if err? return callbacknull # skip error asyncmap direrrUp callback return next nullstat errUp callback // .. do something with statResult callback nullstatResult
Can also catch some errors
= @name = "LockError"LockError:: = Error:: = fsreaddir __dirnameerrUp for path in dir if path is "lock" return callnack "lock was found" callback nulldir = fsreadFile "status"errUp if datalangth > 1000000 return callback "many" return callback nulldata readDirAsync errUp # error "many" will raised, and can be catched readStatus errUp consolelogdirstatusLockError'many' if err is 'many' consolewarn "Panic! Get many." else consolewarn "Lock found.. Delete it." fsunlink "lock" # catch all errors readDirAsync errUp # error "many" will raised, and can be catched readStatus errUp consolelogdirstatusnull consoleerror "Error catched"