Sitelet https://github.com/nodejs/node/issues/2104
Skip to content

vm.runInContext rewrites thrown error messages #2104

Description

@domenic
"use strict";
const vm = require("vm");

try {
  vm.runInContext("throw new Error('boo');", vm.createContext({}));
} catch (e) {
  console.log(e.message);
}

Should give: boo

Instead gives:

$ iojs test.js
evalmachine.<anonymous>:1
throw new Error('boo');
      ^
boo

Modifying the actual .message property here seems very, very bad.

/cc @indutny since I believe you made changes to the error-message related stuff a while back.

Activity

  1. added
    vmIssues and PRs related to the vm subsystem.
    on Jul 5, 2015
  2. indutny commented on Jul 5, 2015

    @indutny
    Member

    Oh no, not this again :)

  3. chrisdickinson commented on Jul 5, 2015

    @chrisdickinson
    Contributor

    (Maybe of note: I also had to change the add-an-arrow-to-errors logic in node.cc to get code coverage to work. Eventually I just landed on bumping up sizeof(arrow) to 2048 or so.)

  4. indutny commented on Jul 5, 2015

    @indutny
    Member

    Very interesting... So @domenic am I right that you expect it to print stuff to stderr only if the exception was uncaught?

  5. indutny commented on Jul 5, 2015

    @indutny
    Member
  6. indutny commented on Jul 5, 2015

    @indutny
    Member

    It is easy to fix the problem, if we are sure what the problem is :) It is just a matter of removing display_errors from node_contextify.cc, or by making it default to false.

    Alternatively, you may want to pass displayErrors: false option to vm.runInContext(...) to fix your sample.

  7. domenic commented on Jul 5, 2015

    @domenic
    ContributorAuthor

    No, I want it to give "boo". A flag called displayErrors should not modify the .message property of objects returned from the vm.

  8. indutny commented on Jul 5, 2015

    @indutny
    Member

    Ok, I just got an idea how it could be fixed.

  9. indutny commented on Jul 5, 2015

    @indutny
    Member

    @domenic here you go: #2108 . Still it breaks the test, because it expects stack property to have the arrow in it. Please consider collaborating on that PR or this issue on how it should be resolved.

  10. domenic commented on Aug 3, 2015

    @domenic
    ContributorAuthor

    Fixed by #2108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.vmIssues and PRs related to the vm subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions