VM: options.columnOffset has no effect on column number in stack trace outputΒ #26780
Copy link
Copy link
Closed
Labels
docIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.Issues that need assistance from volunteers or PRs that need help to proceed.questionIssues asking questions about Node.js.Issues asking questions about Node.js.vmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
Description
- Version: v10.3.0 and v10.15.2
- Platform: Linux ip-172-30-3-105 4.14.42-52.37.amzn1.x86_64
- Subsystem: vm
In vm.runInNewContext (and maybe other versions of "run", too), the options.columnOffset has no effect. I've tried a couple of intentionally-caused errors with various columnOffset values (ranging from -5 to 5), but the character position reported in the stack trace (via e.stack) is always the same. Note that lineOffset works as expected.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
docIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.Issues that need assistance from volunteers or PRs that need help to proceed.questionIssues asking questions about Node.js.Issues asking questions about Node.js.vmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
Activity
devsnek commentedon Mar 19, 2019
I can't reproduce this in 10.15.3
Eric24 commentedon Mar 19, 2019
@devsnek : Yes, I get the same results with your example, but it appears to only work when the VM code is a single line. I've created a stripped-down version of my code that shows the one change that makes it work or not:
In this example,
columnOffsetis ignored:But in this example, it works:
Note that the only difference is whether
codehas an extra newline. In my real code, the source JS is loaded from a file, and typically contains many newlines, but this example (using either a template as show or a simple string with\ncharacters) shows the difference. That's why it was never working for me (I hadn't tried a simple one-line code test).PS - The "line" difference between the two examples is expected, and this is easily adjusted using
lineOffiset, which works fine in both cases.devsnek commentedon Mar 19, 2019
The column offset only affects the first line. The reason column offset exists is for script tags in html:
Every line that isn't the first script tag line has a correct column no matter what, because they start fromt the 1st column. But the source of the js in the first line is offset by 10 (
" <script>"), so in order to display the correctly attribute an error to the location of the code within an html document, the offset is used here.Eric24 commentedon Mar 19, 2019
Hmmm. OK. I guess that explains what I'm seeing. If it's only supposed to affect the first line, then maybe this is just a documentation update.
jasnell commentedon Jun 19, 2020
Marking this as a good first issue doc update.
harshilparmar commentedon Aug 4, 2020
@jasnell Can I do this?
jasnell commentedon Aug 4, 2020
Please feel free!
harshilparmar commentedon Aug 5, 2020
@jasnell I am adding Note beside columnOffset definition
here https://nodejs.org/api/vm.html#vm_vm_runinnewcontext_code_contextobject_options
Is it correct? Please correct me if I am wrong!!
swallville commentedon Dec 3, 2020
Hi @jasnell , I don't known if this doc issue update was already made, but, if not, could I give it a shot?
jasnell commentedon Dec 31, 2020
sorry, just saw the notification on this. It appears that this is still up for someone to take on!
doc: clarify that columnOffset applies only to the first line
doc: clarify that columnOffset applies only to the first line
doc: clarify that columnOffset applies only to the first line
doc: clarify that columnOffset applies only to the first line