Skip to content

Instantly share code, notes, and snippets.

@19h
Last active December 15, 2015 15:28
Show Gist options
  • Select an option

  • Save 19h/5281658 to your computer and use it in GitHub Desktop.

Select an option

Save 19h/5281658 to your computer and use it in GitHub Desktop.
Custom /require/ with exception handler for V8 (Node).
try {delete e;e;}catch(e){v8=e.stack!=void 0}finally{v8=v8||0}
var _$ = require;
require = function(k) {
try {
return _$(k);
} catch (e) {
if (v8) {
(_ = e.stack.split("\n"), __ = "");
for (var a in _) null != _[a].match(/\(([^)]+)\)/g) && (__ += Array(+a + 1).join(" ") + "=> " + _[a].match(/\(([^)]+)\)/g) + "\n");
console.log(_[0], "[" + k + "]\n", __), process.exit();
} else {
console.trace("=== FATAL ERROR: \"" + k + "\" ==="), process.exit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment