Skip to content

fs: do not pass Buffer when toString() fails - #9670

Merged
mscdex merged 1 commit into
nodejs:masterfrom
mscdex:fs-tostring-failure-callback
Dec 14, 2016
Merged

fs: do not pass Buffer when toString() fails#9670
mscdex merged 1 commit into
nodejs:masterfrom
mscdex:fs-tostring-failure-callback

Conversation

@mscdex

@mscdexmscdex commented Nov 18, 2016

Copy link
Copy Markdown
Contributor
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/

@mscdexmscdex 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-botnodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label Nov 18, 2016

@targostargos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@sam-githubsam-github left a comment

Copy link
Copy Markdown
Contributor

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?

Comment threadlib/fs.js Outdated

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done.

@mscdex
mscdexforce-pushed the fs-tostring-failure-callback branch from 733e8e6 to 7b18106CompareNovember 18, 2016 19:51
@mscdex

mscdex commented Nov 18, 2016

Copy link
Copy Markdown
ContributorAuthor

@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
Copy Markdown
ContributorAuthor

@mscdex

mscdex commented Dec 14, 2016

Copy link
Copy Markdown
ContributorAuthor

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
mscdexforce-pushed the fs-tostring-failure-callback branch from dc918d7 to f3cf8e9CompareDecember 14, 2016 08:31
@mscdex
mscdex merged commit f3cf8e9 into nodejs:masterDec 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>
@jasnelljasnell mentioned this pull request Apr 4, 2017
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fsIssues and PRs related to the fs subsystem / file system.semver-majorPRs 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

@mscdex@sam-github@jasnell@thefourtheye@princejwesley@targos@cjihrig@nodejs-github-bot