Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error information not printed for errors thrown while evaluating using vm.runInContext #1658

Closed
platy opened this issue Apr 17, 2015 · 3 comments
Labels
status: waiting for author waiting on response from OP - more information needed

Comments

@platy
Copy link

platy commented Apr 17, 2015

It looks like the runtime formats the error message in a different way for vm.runInContext and mocha seems to have trouble and doesn't print the message at all.

Test:

var vm = require('vm');
require('should');

describe("BDD framework", function(){
    it("throws an undefined error", function() {
        //(function() {
            undefined();
        //}).should.throw(/undefined is not a function/);
    });

    it("throws an undefined error from a runInContext", function() {
        //(function() {
            vm.runInContext('undefined();', vm.createContext({}), {showErrors: true});
        //}).should.throw(/undefined is not a function/);
    });
});

Mocha output:

  0 passing (19ms)
  2 failing

  1) BDD framework throws an undefined error:
     TypeError: undefined is not a function
      at Context.<anonymous> (spec/mocha-problem-spec.js:7:13)

  2) BDD framework throws an undefined error from a runInContext:
     Error: the error {} was thrown, throw an Error :)

Jasmine output:

Failures:
1) BDD framework throws an undefined error
  Message:
    TypeError: undefined is not a function
  Stack:
    TypeError: undefined is not a function
        at Object.<anonymous> (/Users/mikebush/Workspace/spec-verify/spec/mocha-problem-spec.js:7:13)

2) BDD framework throws an undefined error from a runInContext
  Message:
    TypeError: evalmachine.<anonymous>:1
    undefined();
    ^
    undefined is not a function
  Stack:
    evalmachine.<anonymous>:1
    undefined();
    ^
    TypeError: undefined is not a function
        at evalmachine.<anonymous>:1:1
        at Object.exports.runInContext (vm.js:64:17)
        at Object.<anonymous> (/Users/mikebush/Workspace/spec-verify/spec/mocha-problem-spec.js:13:16)
@boneskull
Copy link
Contributor

looks like vm.runInContext won't throw an actual Error for reasons unknown to me. if anyone has any further information on why (or if this is some sort of bug), I'd like to know...

in the meantime:

try {
  vm.runInContext()
} catch (e) {
  throw new Error(e);
}

@boneskull boneskull added the status: waiting for author waiting on response from OP - more information needed label Apr 26, 2015
@platy
Copy link
Author

platy commented Sep 13, 2015

Thanks, I missed this reply up until now.

It looks like the way runInContext throws is fixed in v4.0.0 nodejs/node#2108

@danielstjules
Copy link
Contributor

This was likely fixed as part of #1758 as well :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for author waiting on response from OP - more information needed
Projects
None yet
Development

No branches or pull requests

3 participants