Skip to content

Instantly share code, notes, and snippets.

@nebulade
Created October 17, 2013 17:10
Show Gist options
  • Save nebulade/7028635 to your computer and use it in GitHub Desktop.
Save nebulade/7028635 to your computer and use it in GitHub Desktop.
Safetydance via Warp
'use strict';
var fs = require('fs');
function Warp() {
this.errno = null;
}
Warp.prototype.me = function(func) {
var ret = null;
try {
ret = func.apply(null, Array.prototype.slice.call(arguments, 1));
this.errno = null;
} catch (e) {
this.errno = e;
}
return ret;
};
var w = new Warp();
console.log('Result', w.me(fs.unlinkSync, 'foobar'));
console.log('Error', w.errno);
console.log('Result', w.me(fs.writeFileSync, 'foobar', 'data'));
console.log('Error', w.errno);
console.log('Result', w.me(fs.unlinkSync, 'foobar'));
console.log('Error', w.errno);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment