Browse Source

require() should throw error if module does.

Reported by Kris Zyp
http://groups.google.com/group/nodejs/browse_thread/thread/1feab0309bd5402b
v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
bfa36136da
  1. 5
      src/node.js
  2. 1
      test/mjsunit/fixtures/throws_error.js
  3. 10
      test/mjsunit/test-module-loading.js

5
src/node.js

@ -892,7 +892,12 @@ Module.prototype.loadScript = function (filename, loadPromise) {
+ "\n}; __wrap__;";
var compiledWrapper = process.compile(wrapper, filename);
try {
compiledWrapper.apply(self.exports, [self.exports, require, self, filename]);
} catch (e) {
loadPromise.emitError(e);
return;
}
self.waitChildrenLoad(function () {
self.loaded = true;

1
test/mjsunit/fixtures/throws_error.js

@ -0,0 +1 @@
throw new Error("blah");

10
test/mjsunit/test-module-loading.js

@ -33,6 +33,14 @@ assert.equal("D", d3.D());
assert.equal(true, d4.D instanceof Function);
assert.equal("D", d4.D());
var errorThrown = false;
try {
require("./fixtures/throws_error");
} catch (e) {
errorThrown = true;
assert.equal("blah", e.message);
}
process.addListener("exit", function () {
assert.equal(true, a.A instanceof Function);
assert.equal("A done", a.A());
@ -49,5 +57,7 @@ process.addListener("exit", function () {
assert.equal(true, d2.D instanceof Function);
assert.equal("D done", d2.D());
assert.equal(true, errorThrown);
puts("exit");
});

Loading…
Cancel
Save