Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
test: improve coverage of lib/fs.js#38604
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
test/parallel/test-fs-write-file.js Outdated
| constreadOnlyOption={mode: fs.constants.O_RDONLY,flag: 'r'}; | ||
| fs.writeFile(filename3,s,readOnlyOption,common.expectsError({ | ||
| code: 'EBADF', | ||
| message: 'EBADF: bad file descriptor, write' |
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.
Not a change to make in this PR, but I wonder if that error message could be improved. Unless I'm misunderstanding, the problem from the user perspective is mode/permissions and not that the file descriptor is bad.
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.
Agreed. Since writeFile(fd) and writeFile(path) share the same util function writeAll, this change may need a refactor.
I'll open an issue to track it and look into it later.
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.
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.
According to https://man7.org/linux/man-pages/man2/write.2.html:
EBADF: fd is not a valid file descriptor or is not open for writing.EPERM: The operation was prevented by a file seal; see fcntl(2).
Considering that the file has been opened in the read-only mode and the program is attempting to write to it, isn't EBADF more appropriate here?
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 guess the point is that it's a writeFile operation in the user perspective, but the current error is about file descriptor, which may causes confusing.
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.
This function just reflects the error that is returned from uv_fs_write, which again reflects the error the OS returns. I don't think we replace the error codes for the other functions, so doing it for this particular function feels a little odd, don't you think?
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.
@pd4d10 This test is failing for Windows. Could you please update it to expect an EPERM for Windows?
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading. Please reload this page.
RaisinTen commented May 18, 2021
Removing the |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Darshan Sen <[email protected]>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nodejs-github-bot commented May 21, 2021 • edited by jasnell
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by jasnell
Uh oh!
There was an error while loading. Please reload this page.
jasnell commented May 21, 2021
Landed in a1f590e |
PR-URL: #38604 Refs: https://coverage.nodejs.org/coverage-29f1b609ba5d12d3/lib/fs.js.html#L2045 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
PR-URL: #38604 Refs: https://coverage.nodejs.org/coverage-29f1b609ba5d12d3/lib/fs.js.html#L2045 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
richardlau commented Jul 16, 2021
This lands cleanly on v14.x-staging but the modified test fails I tried adding at the beginning of the test file but still get an error: |
Refs:
https://coverage.nodejs.org/coverage-29f1b609ba5d12d3/lib/fs.js.html#L2045
https://coverage.nodejs.org/coverage-29f1b609ba5d12d3/lib/fs.js.html#L2056