Skip to content

Instantly share code, notes, and snippets.

@azu
Last active May 24, 2018 13:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azu/9700273 to your computer and use it in GitHub Desktop.
Save azu/9700273 to your computer and use it in GitHub Desktop.
node vm + domain error handling
setTimeout(function () {
throw new Error("local error");
},16);
/**
* Created by azu on 2014/03/22.
* LICENSE : MIT
*/
"use strict";
var vm = require("vm");
var fs = require("fs");
var domain = require('domain');
var code = fs.readFileSync(__dirname + "/test/fixtures/async-code.js", "utf-8");
var d = domain.create();
var context = {};
for (var k in global) {
context[k] = global[k];
}
d.on('error', function (error) {
console.log("Error", error.message);
});
d.run(function () {
vm.runInNewContext(code, context);
});
console.log("done");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment