-
Notifications
You must be signed in to change notification settings - Fork 30k
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: do not pass Buffer when toString() fails #9670
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the bufer useful? Particularly here, converting the Buffer to a string failed, but the buffer was sucessfully read, so why not return the data?
@@ -406,7 +406,7 @@ function readFileAfterClose(err) { | |||
else | |||
buffer = context.buffer; | |||
|
|||
if (err) return callback(err, buffer); | |||
if (err) return callback(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this move to line 401, before the buffer object (which is no longer being passed), goes through the code to create/change it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
733e8e6
to
7b18106
Compare
@sam-github I think it's more confusing not only because we don't do that for any other node core API (that I am aware of) but because if you asked for a string, I would never expect a Buffer -- whether there was an error or not. Also, the Buffer is probably useless in most cases since there is usually a reason why a string was requested. |
EDIT: CI is green |
7b18106
to
dc918d7
Compare
Even though an Error object is passed to the callback when readFile() fails due to toString() failing, it is a bit strange to still see data passed as the second argument. This commit changes that and only passes the Error object in that case. PR-URL: nodejs#9670 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
dc918d7
to
f3cf8e9
Compare
Even though an Error object is passed to the callback when readFile() fails due to toString() failing, it is a bit strange to still see data passed as the second argument. This commit changes that and only passes the Error object in that case. PR-URL: nodejs#9670 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Checklist
make -j8 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
Description of change
Even though an Error object is passed to the callback when
readFile()
fails due totoString()
failing, it is a bit strange to still see data passed as the second argument. This commit changes that and onlypasses the Error object in that case.
CI: https://ci.nodejs.org/job/node-test-pull-request/4877/