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

Invalid line is displayed when re-throwing an error #36484

Closed
MrQubo opened this issue Dec 11, 2020 · 1 comment
Closed

Invalid line is displayed when re-throwing an error #36484

MrQubo opened this issue Dec 11, 2020 · 1 comment
Labels
wrong repo Issues that should be opened in another repository.

Comments

@MrQubo
Copy link

MrQubo commented Dec 11, 2020

What steps will reproduce the bug?

Run the following code with node:

try {
	throw new Error('test');
} catch (error) {
	throw error;
}

What do you see instead?

This is the output on stderr:

/tmp/test.js:4
        throw error;
        ^

Error: test
    at Object.<anonymous> (/tmp/test.js:2:8)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:973:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47

What is the expected behavior?

It should highlight the second line instead of fourth. Like this (but see Additional information):

/tmp/test.js:2
        throw new Error('test');
        ^

Error: test
    at Object.<anonymous> (/tmp/test.js:2:8)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:973:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47

Additional information

Fourth line is hightlighted, but not included in the stacktrace, see #36485. Taking also that issue in the account the expected output would be something along those lines:

/tmp/test.js:2
        throw new Error('test');
        ^

Error: test
    at ???? (/tmp/test.js:4:8)
    at Object.<anonymous> (/tmp/test.js:2:8)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:973:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47

But I'm not sure what should come in the place of ????.

@aduh95
Copy link
Contributor

aduh95 commented Dec 12, 2020

The highlighted line is the one which threw the error. This behaviour is produced by V8 (the JS engine Node.js is using), you can reproduce the same behaviour on Chrome browsers as well:

VM65:4 Uncaught Error: test
    at <anonymous>:2:8

If you don't like this behaviour, you can open an issue on the V8 issue tracker.

@aduh95 aduh95 closed this as completed Dec 12, 2020
@aduh95 aduh95 added the wrong repo Issues that should be opened in another repository. label Dec 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wrong repo Issues that should be opened in another repository.
Projects
None yet
Development

No branches or pull requests

2 participants