Created
October 17, 2013 17:10
-
-
Save nebulade/7028635 to your computer and use it in GitHub Desktop.
Safetydance via Warp
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
'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