src: report libuv error when openAsBlob cannot stat · nodejs/node@9c46e56 · GitHub
Skip to content

Commit 9c46e56

Browse files
bitpshraduh95
authored andcommitted
src: report libuv error when openAsBlob cannot stat
`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: #65514 Signed-off-by: Paul Bouchon <mail@bitpshr.net> PR-URL: #65517 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 2ce0e2e commit 9c46e56

4 files changed

Lines changed: 33 additions & 7 deletions

File tree

‎src/dataqueue/queue.cc‎

Lines changed: 11 additions & 4 deletions

‎src/dataqueue/queue.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,11 @@ class DataQueue : public MemoryRetainer {
226226
static std::unique_ptr<Entry> CreateDataQueueEntry(
227227
std::shared_ptr<DataQueue> data_queue);
228228

229+
// Returns nullptr if the file cannot be stat'd. When `status` is given, it
230+
// is set to the libuv error code so callers can report why.
229231
static std::unique_ptr<Entry> CreateFdEntry(Environment* env,
230-
v8::Local<v8::Value> path);
232+
v8::Local<v8::Value> path,
233+
int* status = nullptr);
231234

232235
// Creates a Reader for the given queue. If the queue is idempotent,
233236
// any number of readers can be created, all of which are guaranteed

‎src/node_blob.cc‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@ void BlobFromFilePath(const FunctionCallbackInfo<Value>& args) {
110110
ToNamespacedPath(env, &path);
111111
THROW_IF_INSUFFICIENT_PERMISSIONS(
112112
env, permission::PermissionScope::kFileSystemRead, path.ToStringView());
113-
auto entry = DataQueue::CreateFdEntry(env, args[0]);
113+
int status = 0;
114+
auto entry = DataQueue::CreateFdEntry(env, args[0], &status);
114115
if (entry == nullptr) {
115-
return THROW_ERR_INVALID_ARG_VALUE(env, "Unable to open file as blob");
116+
// The file could not be stat'd. Report the libuv error so callers can tell
117+
// ENOENT apart from any other reason the path could not be used.
118+
return env->ThrowUVException(status, "stat", nullptr, *path);
116119
}
117120

118121
std::vector<std::unique_ptr<DataQueue::Entry>> entries;

‎test/parallel/test-blob-file-backed.js‎

Lines changed: 13 additions & 0 deletions

0 commit comments

Comments
 (0)