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: do not pass Buffer when toString() fails #9670

Merged
merged 1 commit into from
Dec 14, 2016

Conversation

mscdex
Copy link
Contributor

@mscdex mscdex commented Nov 18, 2016

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)
  • fs
Description of change

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.

CI: https://ci.nodejs.org/job/node-test-pull-request/4877/

@mscdex mscdex added fs Issues and PRs related to the fs subsystem / file system. semver-major PRs that contain breaking changes and should be released in the next major version. labels Nov 18, 2016
@nodejs-github-bot nodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label Nov 18, 2016
Copy link
Member

@targos targos left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@sam-github sam-github left a 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);
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@mscdex mscdex force-pushed the fs-tostring-failure-callback branch from 733e8e6 to 7b18106 Compare November 18, 2016 19:51
@mscdex
Copy link
Contributor Author

mscdex commented Nov 18, 2016

@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.

@mscdex
Copy link
Contributor Author

mscdex commented Nov 18, 2016

@mscdex
Copy link
Contributor Author

mscdex commented Dec 14, 2016

CI before landing: https://ci.nodejs.org/job/node-test-pull-request/5399/
CI before landing: https://ci.nodejs.org/job/node-test-pull-request/5400/

EDIT: CI is green

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>
@mscdex mscdex force-pushed the fs-tostring-failure-callback branch from dc918d7 to f3cf8e9 Compare December 14, 2016 08:31
@mscdex mscdex merged commit f3cf8e9 into nodejs:master Dec 14, 2016
@mscdex mscdex deleted the fs-tostring-failure-callback branch December 14, 2016 08:34
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 18, 2017
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>
@jasnell jasnell mentioned this pull request Apr 4, 2017
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. 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.

8 participants