Skip to content

Commit

Permalink
src: pass syscall on fs.readFileSync fail operation
Browse files Browse the repository at this point in the history
PR-URL: #48815
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
anonrig committed Jul 17, 2023
1 parent 6515b3b commit 339eb10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/internal/fs/read/utf8.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
14 changes: 11 additions & 3 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,7 @@ static inline Maybe<void> CheckOpenPermissions(Environment* env,

static void ReadFileSync(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
auto isolate = env->isolate();

CHECK_GE(args.Length(), 2);

Expand All @@ -1980,8 +1981,11 @@ static void ReadFileSync(const FunctionCallbackInfo<Value>& 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<Value> 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);

Expand All @@ -2001,8 +2005,12 @@ static void ReadFileSync(const FunctionCallbackInfo<Value>& args) {
if (req.result < 0) {
FS_SYNC_TRACE_END(read);
// req will be cleaned up by scope leave.
Local<Value> 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) {
Expand Down

0 comments on commit 339eb10

Please sign in to comment.