X Tutup
The Wayback Machine - https://web.archive.org/web/20220924131351/https://github.com/nodejs/node/pull/44769
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

fs: add validateBuffer to improve error #44769

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

wafuwafu13
Copy link
Contributor

@wafuwafu13 wafuwafu13 commented Sep 24, 2022

when params is { buffer: null }, buffer is not initialized with Buffer.alloc(16384). so error message became not user-friendly as seen in test case.

node/lib/fs.js

Line 621 in abfeed8

({ buffer = Buffer.alloc(16384) } = params ?? kEmptyObject);

@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Sep 24, 2022
{
name: 'TypeError',
message: 'The "buffer" argument must be an instance of Buffer, ' +
'TypedArray, or DataView. Received null',
},
Copy link
Contributor

@aduh95 aduh95 Sep 24, 2022

Choose a reason for hiding this comment

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

Let's not validate the message, but rather the error code.

Suggested change
{
name: 'TypeError',
message: 'The "buffer" argument must be an instance of Buffer, ' +
'TypedArray, or DataView. Received null',
},
{ code: 'ERR_INVALID_ARG_TYPE' },

Copy link
Contributor Author

@wafuwafu13 wafuwafu13 Sep 24, 2022

Choose a reason for hiding this comment

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

👍 fixed b7ba2c3

@aduh95
Copy link
Contributor

aduh95 commented Sep 24, 2022

/cc @nodejs/fs

@aduh95 aduh95 added the semver-major PRs that contain breaking changes and should be released in the next major version. label Sep 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants
X Tutup