fs: do not pass Buffer when toString() fails#9670
Conversation
sam-github
left a comment
There was a problem hiding this comment.
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?
lib/fs.js
Outdated
There was a problem hiding this comment.
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?
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/