nodejs / nodejs/node

fs async functions (both callback and promises APIs) return Errors without stack trace

Open
#30,944 17 comments 29 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

confirmed-bug fs
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

  • Version: 13.3.0
  • Platform: Windows 10 x64
const fs = require('fs')
fs.readFile('nonexistentfile', (err) => console.log(err.stack))

What is the expected output?
The err.stack should contain error text and stack
Same as readFileSync function:

Error: ENOENT: no such file or directory, open 'nonexistentfile'
at Object.openSync (fs.js:446:3)
at Object.readFileSync (fs.js:348:35)
...

What do you see instead?
err.stack only contains error text

Error: ENOENT: no such file or directory, open 'C:\dev\projects\ntest\nonexistentfile'

fs.writeFile have same trouble
Аnother strange thing is that the error text is also different (local/absolute path)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the fs.readFile and fs.writeFile callback cases on the reported Node.js version, then compare their errors with readFileSync. Check the corresponding promise APIs as well; done means asynchronous errors include a stack trace and use the expected path and error text.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.