-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: simplify the error context collection in C++, migrate fs.close errors #17338
Conversation
6045b01
to
00e4029
Compare
test/parallel/test-fs-close-error.js
Outdated
assert.throws( | ||
() => { fs.closeSync(-1); }, | ||
(err) => { | ||
assert.strictEqual(err.code, 'EBADF'); |
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.
The current error does not include any information about the fd
being closed (I think it's also the same for other fs APIs that takes fd as arguments). To improve this properly we would need to update the After
callback so that async APIs can be consistent with the synchronous APIs. We could add fd
as an argument to UVException
but IMO that's just going to bloat the signature of that function even further, putting those data in an object in JS is much more flexible.
Since After
is also used by functions not migrated yet, I would like to update this bit when all the fs errors are migrated to the JS layer.
00e4029
to
7f3f9d9
Compare
Slight bit of overlap with this: #17334 |
@joyeecheung ... in #17334 I'm going to be focusing entirely on moving the input arg validation out into javascript. To make it easier on us both, how about focusing this PR only on the other errors then we can meet in the middle :-) |
@jasnell ACK, thanks, I only migrated those type checks in this PR as well because since I was migrating |
7f3f9d9
to
0309a8a
Compare
Removed the type checks in favor of #17334 |
This is no longer semver major, but defensively adding the don't land labels until #17160 is backported in non-semver-major fashion |
|
||
let message = `${ctx.code}: ${ctx.message}, ${ctx.syscall}`; | ||
for (const prop of Object.keys(ctx)) { | ||
if (prop === 'message' || prop === 'path' || prop === 'dest') { |
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.
The message will actually not show up because it should be non-enumerable
. If ctx
is a regular error.
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.
Ignore me, I should have checked what ctx
stands for. When I commented first it seemed like a error.
lib/internal/errors.js
Outdated
if (prop === 'message' || prop === 'path' || prop === 'dest') { | ||
continue; | ||
} | ||
err[prop] = ctx; |
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.
I think you wanted to write ctx[prop]
instead of ctx
.
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.
JS part LGTM besides the comment. The rest is also LG as far as I can tell.
0309a8a
to
4fcf4ee
Compare
Rebased now that the type checking tests have landed. Also validate the |
CI: https://ci.nodejs.org/job/node-test-commit/15076/ Minimized the changes to node_file.cc and split the uv binding changes to a separate commit. CI is green now minus one unrelated failure. @jasnell @BridgeAR PTAL. |
still lgtm |
Landed in 24c71fb...9f122e3, thanks! |
Add a errno -> [error code, uv error message] map to the uv binding so the error message can be assembled in the JS layer. PR-URL: #17338 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
- Simplify the SyncCall template function, only collect error number and syscall in the C++ layer and collect the rest of context in JS for flexibility. - Remove the stringFromPath JS helper now that the unprefixed path is directly put into the context before the binding is invoked with the prefixed path. - Validate more properties in fs.access tests. PR-URL: #17338 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
* Collect the error context in both JS and C++, then throw the error in JS * Test that the errors thrown from fs.close and fs.closeSync includes the correct error code, error number and syscall properties PR-URL: #17338 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Add a errno -> [error code, uv error message] map to the uv binding so the error message can be assembled in the JS layer. PR-URL: nodejs#17338 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Add a errno -> [error code, uv error message] map to the uv binding so the error message can be assembled in the JS layer. PR-URL: nodejs#17338 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
fs: simplify the error context collection in C++
number and syscall in the C++ layer and collect the rest of context
in JS for flexibility.
directly put into the context before the binding is invoked with the
prefixed path.
so the error message can be assembled in the JS layer
fs: throw fs.close errors in JS
ERR_INVALID_ARG_TYPE if it's not an integer
fs.closeSync
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
fs, test, errors