src: report libuv error when openAsBlob cannot stat - #65517
Open
bitpshr wants to merge 1 commit into
Open
Conversation
`FdEntry::Create()` returned nullptr for any failed `uv_fs_stat()`, discarding the status, and `BlobFromFilePath()` turned that into `ERR_INVALID_ARG_VALUE: Unable to open file as blob`. A missing file is not a malformed argument, and the resulting `TypeError` carried no `errno`, `syscall`, or `path`, so ENOENT could not be told apart from any other reason the path was unusable. Thread the libuv status out of `CreateFdEntry()` and throw a `UVException` instead, so `fs.openAsBlob()` reports the same error `fs.stat()` does for the same path. Fixes: nodejs#65514 Signed-off-by: Paul Bouchon <mail@bitpshr.net>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65517 +/- ##
==========================================
- Coverage 90.21% 90.16% -0.06%
==========================================
Files 751 751
Lines 253550 253589 +39
Branches 47813 47782 -31
==========================================
- Hits 228733 228640 -93
- Misses 16076 16207 +131
- Partials 8741 8742 +1
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #65514
FdEntry::Create()dropped theuv_fs_stat()status and returnednullptr, soBlobFromFilePath()reported every failure asERR_INVALID_ARG_VALUE: Unable to open file as blob. A missing file is not a malformed argument, and theTypeErrorhad noerrno,syscall, orpathto work with. This threads the status out and throws aUVExceptioninstead:which matches what
fs.stat()reports for the same path,errno/syscall/pathincluded.Two notes:
statonly needs traversal permission on the parent, so an unreadable file still opens fine and fails later at read time withNotReadableError. The stat failures this affects are ENOENT, ENOTDIR, ELOOP and friends.fs.openAsBlob#62655 fixes the separate sync-throw half of fs.openAsBlob reports a missing file as ERR_INVALID_ARG_VALUE, discarding the ENOENT #65514 and its new test assertsERR_INVALID_ARG_VALUEfor a missing file, which would need updating if that lands after this. I wrote the test here asassert.rejects(async () => openAsBlob(missing), ...)so it passes either way, and I am happy to fold this into that PR instead if the reviewers there would rather keep it in one place.I also left the directory case alone (
openAsBlob("./some-dir")still succeeds and fails at read time). There is an existingTODO(@jasnell, @flakey5)onFdEntryabout rejecting non-regular files, and that felt like a separate behavior change rather than something to slip in here. Glad to take it on as a follow-up.