From 227e6bd89881a5bb7ff7f9e1f4e62b452c906492 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Mon, 17 Jul 2023 14:29:01 -0400 Subject: [PATCH] src: pass syscall on `fs.readFileSync` fail operation PR-URL: https://github.com/nodejs/node/pull/48815 Reviewed-By: Debadree Chatterjee Reviewed-By: Benjamin Gruenbaum --- lib/internal/fs/read/utf8.js | 3 ++- src/node_file.cc | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/internal/fs/read/utf8.js b/lib/internal/fs/read/utf8.js index e916c918c11190..5159db5988ee0b 100644 --- a/lib/internal/fs/read/utf8.js +++ b/lib/internal/fs/read/utf8.js @@ -16,7 +16,8 @@ function readFileSyncUtf8(path, flag) { return response; } - handleErrorFromBinding({ errno: response, path }); + const { 0: errno, 1: syscall } = response; + handleErrorFromBinding({ errno, syscall, path }); } module.exports = { diff --git a/src/node_file.cc b/src/node_file.cc index 619ba5841e29cd..7667d4153d570e 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1996,6 +1996,7 @@ static inline Maybe CheckOpenPermissions(Environment* env, static void ReadFileSync(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); + auto isolate = env->isolate(); CHECK_GE(args.Length(), 2); @@ -2015,8 +2016,11 @@ static void ReadFileSync(const FunctionCallbackInfo& args) { FS_SYNC_TRACE_END(open); if (req.result < 0) { // req will be cleaned up by scope leave. - return args.GetReturnValue().Set( - v8::Integer::New(env->isolate(), req.result)); + Local out[] = { + Integer::New(isolate, req.result), // errno + FIXED_ONE_BYTE_STRING(isolate, "open"), // syscall + }; + return args.GetReturnValue().Set(Array::New(isolate, out, arraysize(out))); } uv_fs_req_cleanup(&req); @@ -2036,8 +2040,12 @@ static void ReadFileSync(const FunctionCallbackInfo& args) { if (req.result < 0) { FS_SYNC_TRACE_END(read); // req will be cleaned up by scope leave. + Local out[] = { + Integer::New(isolate, req.result), // errno + FIXED_ONE_BYTE_STRING(isolate, "read"), // syscall + }; return args.GetReturnValue().Set( - v8::Integer::New(env->isolate(), req.result)); + Array::New(isolate, out, arraysize(out))); } uv_fs_req_cleanup(&req); if (r <= 0) {