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

fix: improper wrapping of fs.promises.readFile #29528

Merged
merged 2 commits into from
Jun 7, 2021
Merged

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented Jun 3, 2021

Description of Change

Fixes an issue where fs.promises.readFile would improperly error when running e.g:

const path = require('path')
const fs = require('fs');
const {
  open,
  readFile
} = fs.promises;

let fileHandle;
const run = async () => {
  const filePathForHandle = path.join('/Users', 'codebytere', 'Desktop', 'dogs-running.txt');
  fileHandle = await open(filePathForHandle, 'w+');
  const buffer = Buffer.from('Dogs running'.repeat(10000), 'utf8');
  fs.writeFileSync(filePathForHandle, buffer);
  await readFile(fileHandle)
  await fileHandle.close();
}

run();

with:

(node:89865) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of FileHandle
    at readFile (fs.js:326:10)
    at e.readFile (electron/js2c/asar_bundle.js:5:7666)
    at internal/util.js:297:30
    at new Promise (<anonymous>)
    at internal/util.js:296:12
    at run (/private/var/folders/w4/6ckkx75165l174lkz07vgx_m0000gn/T/tmp-29494-eQiOkaJ4iCxZ/main.js:14:9)

becuase our fs wrapper simply used util.promisify on the asar-ified version of fs.readFile instead of calling into Node.js' actual version, which is implemented slightly differently.

Checklist

Release Notes

Notes: Fixd an issue where fs.promises.readFile would improperly error when passing a FileHandle to the path argument.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Jun 3, 2021
@codebytere codebytere added the semver/patch backwards-compatible bug fixes label Jun 3, 2021
Copy link
Member

@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Test? 😉

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Jun 4, 2021
@codebytere codebytere merged commit a4decff into main Jun 7, 2021
@codebytere codebytere deleted the fix-fs-readfile branch June 7, 2021 19:19
@release-clerk
Copy link

release-clerk bot commented Jun 7, 2021

Release Notes Persisted

Fixd an issue where fs.promises.readFile would improperly error when passing a FileHandle to the path argument.

@trop
Copy link
Contributor

trop bot commented Jun 7, 2021

I have automatically backported this PR to "12-x-y", please check out #29575

@trop
Copy link
Contributor

trop bot commented Jun 7, 2021

I have automatically backported this PR to "13-x-y", please check out #29576

@trop
Copy link
Contributor

trop bot commented Jun 7, 2021

I have automatically backported this PR to "14-x-y", please check out #29577

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants