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: fix misplaced errors in fs.symlinkSync #18548

Closed
wants to merge 1 commit into from

Conversation

joyeecheung
Copy link
Member

@joyeecheung joyeecheung commented Feb 3, 2018

The ctx.error is supposed to be handled in fs.readlinkSync,
but was handled in fs.symlinkSync by mistake.

Also fix the error number check in readlink to be consistent
with SYNC_CALL.

Refs: #18348

This is an oversight of #18348, the error handling was supposed to be in fs.readlinkSync instead of fs.symlinkSync. I couldn't come up with a test because these errors cannot be triggered easily:

node/src/string_bytes.cc

Lines 41 to 51 in 1286923

#define SB_MALLOC_FAILED_ERROR \
v8::Exception::Error(OneByteString(isolate, "\"toString()\" failed"))
#define SB_STRING_TOO_LONG_ERROR \
v8::Exception::Error(OneByteString(isolate, "\"toString()\" failed"))
#define SB_BUFFER_CREATION_ERROR \
v8::Exception::Error(OneByteString(isolate, "\"toString()\" failed"))
#define SB_BUFFER_SIZE_EXCEEDED_ERROR \
v8::Exception::Error(OneByteString(isolate, "\"toString()\" failed"))

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

fs

@nodejs-github-bot nodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label Feb 3, 2018
@maclover7
Copy link
Contributor

Should we add a regression test here? Otherwise LGTM

@joyeecheung
Copy link
Member Author

@maclover7 The only way not to introduce more flakes that I can think of is monkey-patching the binding so that it returns ctx with an error...not a big fan of this way of testing but I can add that

@maclover7
Copy link
Contributor

@joyeecheung Hmm, I may be oversimplifying / not completely understanding what's being changed here, but couldn't there be a test that checks the error stacktrace to make sure everything that's there is there? That seems like what the extra conditional provides

@joyeecheung
Copy link
Member Author

@maclover7 The ctx.error is only triggered by the cases described in the OP, e.g. when malloc fails or the buffer to encode is too big. Normal syscall errors don't go there

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

I personally think monkey patching to test this is appropriate but I am ok with landing this without a test as well.

@BridgeAR
Copy link
Member

BridgeAR commented Feb 6, 2018

@joyeecheung can you please always run a CI after creating a PR? :-)

@BridgeAR
Copy link
Member

BridgeAR commented Feb 6, 2018

The ctx.error is supposed to be handled in fs.readlinkSync,
but was handled in fs.symlinkSync by mistake.

Also fix the error number check in readlink to be consistent
with SYNC_CALL.
@joyeecheung
Copy link
Member Author

@joyeecheung
Copy link
Member Author

Landed in b1c6ecb, thanks!

@joyeecheung joyeecheung closed this Feb 8, 2018
joyeecheung added a commit that referenced this pull request Feb 8, 2018
The ctx.error is supposed to be handled in fs.readlinkSync,
but was handled in fs.symlinkSync by mistake.

Also fix the error number check in readlink to be consistent
with SYNC_CALL.

PR-URL: #18548
Refs: #18348
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@MylesBorins
Copy link
Member

Should this be backported to v9.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
The ctx.error is supposed to be handled in fs.readlinkSync,
but was handled in fs.symlinkSync by mistake.

Also fix the error number check in readlink to be consistent
with SYNC_CALL.

PR-URL: nodejs#18548
Refs: nodejs#18348
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants