Skip to content

Correct the error type of fs.writeFile with read-only mode #38607

Description

@pd4d10

Refs: #38604 and #38604 (review)

const file = '/tmp/1.txt'
fs.writeFileSync(file, '') // Create first

fs.writeFile(file, 'hello', { flag: 'r' }, (err) => {
  console.log(err)
  // [Error: EBADF: bad file descriptor, write] {
  //   errno: -9,
  //   code: 'EBADF',
  //   syscall: 'write'
  // }
})

Activity

  1. added
    errorsIssues and PRs related to JavaScript errors originating in Node.js core.
    fsIssues and PRs related to file-system APIs and the fs module.
    on May 9, 2021
  2. RaisinTen commented on May 19, 2021

    @RaisinTen
    Member

    Are you expecting Windows to return an EBADF instead of an EPERM just like Linux does?

  3. RaisinTen commented on May 19, 2021

    @RaisinTen
    Member

    PR to do that: libuv/libuv#3303

  4. RaisinTen commented on Jan 7, 2022

    @RaisinTen
    Member

    The fix landed in #41398, closing! :)

  5. vtjnash commented on Mar 7, 2022

    @vtjnash
    Contributor

    Duplicate of #16596

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    errorsIssues and PRs related to JavaScript errors originating in Node.js core.fsIssues and PRs related to file-system APIs and the fs module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions