Skip to content

Various async fs functions don't have stack trace in resultant Error #34817

Closed
@bberry6

Description

@bberry6
  • Version: Tested on v14.8.0, v12.7.0, v10.22.0, v10.15.3
  • Platform: Darwin bberry-mbp 19.6.0 Darwin Kernel Version 19.6.0: Sun Jul 5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64 x86_64
  • Subsystem: fs

What steps will reproduce the bug?

This case will test fs.readdir. I've also noticed similar problems with lstat (by statting a nonexistent file) and readFile (with a directory as its first parameter).

Create a file (in this case, it is in the same folder as the script, aptly named 'someExistingFile')

const {readdir} = require('fs');
const path = require('path');
readdir(path.join(__dirname, 'someExistingFile'), (e,files) => {
  console.log(e);  // doesnt print stack
  console.log(e.stack);  // also doesn't print stack
});

Output (the Errors are expected):

[Error: ENOTDIR: not a directory, scandir './someExistingFile'] {
  errno: -20,
  code: 'ENOTDIR',
  syscall: 'scandir',
  path: './someExistingFile'
}
Error: ENOTDIR: not a directory, scandir './someExistingFile'

How often does it reproduce? Is there a required condition?

Every time. The required condition is having ./someExistingFile be an existing file, not a folder.

What is the expected behavior?

Print the stack trace of where the error occurred.

What do you see instead?

In the case of console.log(e):

[Error: ENOTDIR: not a directory, scandir './someExistingFile'] {
  errno: -20,
  code: 'ENOTDIR',
  syscall: 'scandir',
  path: './someExistingFile'
}

In the case of console.log(e.stack):
Error: ENOTDIR: not a directory, scandir '/Users/brett/someExistingFile'

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.questionIssues that look for answers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions