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

[feat] [test] Check Error stack for **all** node builtin #49045

Closed
loynoir opened this issue Aug 6, 2023 · 6 comments
Closed

[feat] [test] Check Error stack for **all** node builtin #49045

loynoir opened this issue Aug 6, 2023 · 6 comments
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@loynoir
Copy link

loynoir commented Aug 6, 2023

Search Keyword

  • Errors without stack trace

  • swallow error stack trace

  • no stack trace

  • incomplete stack trace

  • stack trace without script itself

What is the problem this feature will solve?

Actual

Error stack not includes /tmp/reproduce/reproduce.mjs

import { readFile } from 'node:fs/promises'

await readFile('/tmp/notexists')
node:internal/process/esm_loader:46
      internalBinding('errors').triggerUncaughtException(
                                ^

[Error: ENOENT: no such file or directory, open '/tmp/notexists'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/tmp/notexists'
}

Node.js v20.4.0

Expected

Error stack includes /tmp/reproduce/reproduce.mjs

import { readFileSync } from 'node:fs'

await readFileSync('/tmp/notexists')
node:fs:593
  handleErrorFromBinding(ctx);
  ^

Error: ENOENT: no such file or directory, open '/tmp/notexists'
    at Object.openSync (node:fs:593:3)
    at readFileSync (node:fs:461:35)
    at file:///tmp/reproduce/reproduce.mjs:3:7
    at ModuleJob.run (node:internal/modules/esm/module_job:192:25)
    at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24)
    at async loadESM (node:internal/process/esm_loader:40:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/tmp/notexists'
}

Node.js v20.4.0

What is the feature you are proposing to solve the problem?

Given script /tmp/reproduce/reproduce.mjs.

If it throw, expect its error stack should includes /tmp/reproduce/reproduce.mjs

However, seems some node functions not obey that.

Some thoughts.

  1. Is there a full list of these kind of function, which need to be careful?

  2. Would be nice to have test to check error stack include the script itself.

  3. Expect error stack include script itself. Is this by spec? Or is it a convention? Or neither, just a very common case?

What alternatives have you considered?

No response

Related

#30944

@loynoir loynoir added the feature request Issues that request new features to be added to Node.js. label Aug 6, 2023
@github-project-automation github-project-automation bot moved this to Pending Triage in Node.js feature requests Aug 6, 2023
@loynoir loynoir changed the title [test] Check Error stack for **all** node builtin [feat] [test] Check Error stack for **all** node builtin Aug 6, 2023
@aduh95
Copy link
Contributor

aduh95 commented Aug 8, 2023

/cc @nodejs/fs

3. Is this by spec? Or is it a convention? Or neither, just a very common case?

AFAIK there's no spec regarding error stack traces, it's at best a convention, a common case would be a more precise way to put it.

Related

#30944

Isn't that more than just related? It looks like a duplicate to me. What's the difference between the two issues?

@loynoir
Copy link
Author

loynoir commented Aug 9, 2023

AFAIK there's no spec regarding error stack traces, it's at best a convention, a common case would be a more precise way to put it.

The spec should describe such import thing for debug, else, very hard to figure out where goes wrong. 😢

It looks like a duplicate to me. What's the difference between the two issues?

  1. I suggest to check error-stack-include-script-itself to all node builtin function test

  2. Thus, gather a full list, which function user should use carefully (hard to debug stack-trace-missing-script-itself where goes wrong within codebase).

@joyeecheung
Copy link
Member

joyeecheung commented Aug 9, 2023

This is specifically an issue with promise rejected from C++ land, so it's a duplicate of #30944 - the JS spec can't do anything with it, the fact that a JS land readFile() invocation can result in the later creation of an unhandled rejection somewhere (in C++) is a Node.js thing, so it's up to Node.js to thread the JS call site and the C++ rejection site together to create a meaningful stack trace for that rejection. Node.js does not normally keep track of the JS call sites in this case (because if there isn't an error, which is what usually happens, all the bookkeeping would result in a significant overhead for nothing). Although it does keep track of the information when the inspector is enabled - I think the issue described in OP still reproduces when the inspector is enabled, so I think in that case at least something can be done to put the missing pieces together and enhance the stack trace using the existing tracked information.

Copy link
Contributor

github-actions bot commented Feb 6, 2024

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label Feb 6, 2024
@Gonz-coding-co
Copy link

Gonz-coding-co commented Feb 6, 2024 via email

@github-actions github-actions bot removed the stale label Feb 7, 2024
@legendecas
Copy link
Member

Closed in duplicated of #30944.

@legendecas legendecas closed this as not planned Won't fix, can't repro, duplicate, stale Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

No branches or pull requests

5 participants