Skip to content

Misleading error message when recursive fs.mkdir fails with EACCES #31481

Closed
@isaacs

Description

  • Version: v13.4.0
  • Platform: darwin
  • Subsystem: fs
> fs.mkdirSync('/var/this/fails', { recursive: true })
    at Object.mkdirSync (fs.js:854:3) {
  errno: -2,
  syscall: 'mkdir',
  code: 'ENOENT',
  path: '/var/this/fails'
}

> fs.mkdir('/var/this/fails', { recursive: true }, console.error)
undefined
> [Error: ENOENT: no such file or directory, mkdir] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'mkdir'
}

Problems with this error:

  1. No path is provided in the async version. (Reported in missing error.path at fs.mkdir callback on last call #28015)
  2. Error code is ENOENT when it should be EACCES.
  3. Error errno is -2 when it should be -13.

A manual recursive implementation (like make-dir or mkdirp) will fail when it hits this:

> fs.mkdirSync('/var/this', { recursive: false })
Uncaught Error: EACCES: permission denied, mkdir '/var/this'
    at Object.mkdirSync (fs.js:854:3) {
  errno: -13,
  syscall: 'mkdir',
  code: 'EACCES',
  path: '/var/this'
}
> fs.mkdir('/var/this', { recursive: false }, console.error)
undefined
> [Error: EACCES: permission denied, mkdir '/var/this'] {
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path: '/var/this'
}

Note that the recursive: true implementation will fail in the same way with ENOENT even if the parent path does in fact exist and the syscall is failing with EACCES:

> fs.mkdirSync('/var/this', { recursive: true })
Uncaught Error: ENOENT: no such file or directory, mkdir '/var/this'
    at Object.mkdirSync (fs.js:854:3) {
  errno: -2,
  syscall: 'mkdir',
  code: 'ENOENT',
  path: '/var/this'
> fs.mkdir('/var/this', { recursive: true }, console.error)
undefined
> [Error: ENOENT: no such file or directory, mkdir] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'mkdir'
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions