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

vm.runInContext rewrites thrown error messages #2104

Closed
domenic opened this issue Jul 5, 2015 · 9 comments
Closed

vm.runInContext rewrites thrown error messages #2104

domenic opened this issue Jul 5, 2015 · 9 comments
Labels
confirmed-bug Issues with confirmed bugs. vm Issues and PRs related to the vm subsystem.

Comments

@domenic
Copy link
Contributor

domenic commented Jul 5, 2015

"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.

@domenic domenic added the vm Issues and PRs related to the vm subsystem. label Jul 5, 2015
@indutny
Copy link
Member

indutny commented Jul 5, 2015

Oh no, not this again :)

@chrisdickinson
Copy link
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.)

@indutny
Copy link
Member

indutny commented Jul 5, 2015

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

@indutny
Copy link
Member

indutny commented Jul 5, 2015

This test wants it to be completely different: https://github.com/nodejs/io.js/blob/master/test/sequential/test-vm-syntax-error-stderr.js

@indutny
Copy link
Member

indutny commented Jul 5, 2015

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.

@domenic
Copy link
Contributor Author

domenic commented Jul 5, 2015

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

@indutny
Copy link
Member

indutny commented Jul 5, 2015

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

@indutny
Copy link
Member

indutny commented Jul 5, 2015

@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.

indutny added a commit to indutny/io.js that referenced this issue Jul 6, 2015
Put the `...^` arrow string to the hidden property of the object, and
use it only when printing error to the stderr.

Fix: nodejs#2104
PR-URL: nodejs#2108
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
@brendanashworth brendanashworth added the confirmed-bug Issues with confirmed bugs. label Jul 6, 2015
indutny added a commit that referenced this issue Jul 17, 2015
Put the `...^` arrow string to the hidden property of the object, and
use it only when printing error to the stderr.

Fix: #2104
PR-URL: #2108
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
indutny added a commit that referenced this issue Jul 22, 2015
Put the `...^` arrow string to the hidden property of the object, and
use it only when printing error to the stderr.

Fix: #2104
PR-URL: #2108
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
indutny added a commit that referenced this issue Jul 24, 2015
Put the `...^` arrow string to the hidden property of the object, and
use it only when printing error to the stderr.

Fix: #2104
PR-URL: #2108
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
indutny added a commit that referenced this issue Jul 30, 2015
Put the `...^` arrow string to the hidden property of the object, and
use it only when printing error to the stderr.

Fix: #2104
PR-URL: #2108
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
indutny added a commit that referenced this issue Aug 1, 2015
Put the `...^` arrow string to the hidden property of the object, and
use it only when printing error to the stderr.

Fix: #2104
PR-URL: #2108
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
@domenic
Copy link
Contributor Author

domenic commented Aug 3, 2015

Fixed by #2108

@domenic domenic closed this as completed Aug 3, 2015
indutny added a commit that referenced this issue Aug 3, 2015
Put the `...^` arrow string to the hidden property of the object, and
use it only when printing error to the stderr.

Fix: #2104
PR-URL: #2108
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
indutny added a commit that referenced this issue Aug 4, 2015
Put the `...^` arrow string to the hidden property of the object, and
use it only when printing error to the stderr.

Fix: #2104
PR-URL: #2108
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
indutny added a commit that referenced this issue Aug 4, 2015
Put the `...^` arrow string to the hidden property of the object, and
use it only when printing error to the stderr.

Fix: #2104
PR-URL: #2108
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants