Skip to content

Commit 227e6bd

Browse files
anonrigjuanarbol
authored andcommitted
src: pass syscall on fs.readFileSync fail operation
PR-URL: #48815 Reviewed-By: Debadree Chatterjee <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent ef7728b commit 227e6bd

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/internal/fs/read/utf8.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ function readFileSyncUtf8(path, flag) {
1616
return response;
1717
}
1818

19-
handleErrorFromBinding({ errno: response, path });
19+
const { 0: errno, 1: syscall } = response;
20+
handleErrorFromBinding({ errno, syscall, path });
2021
}
2122

2223
module.exports = {

src/node_file.cc

+11-3
Original file line numberDiff line numberDiff line change
@@ -1996,6 +1996,7 @@ static inline Maybe<void> CheckOpenPermissions(Environment* env,
19961996

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

20002001
CHECK_GE(args.Length(), 2);
20012002

@@ -2015,8 +2016,11 @@ static void ReadFileSync(const FunctionCallbackInfo<Value>& args) {
20152016
FS_SYNC_TRACE_END(open);
20162017
if (req.result < 0) {
20172018
// req will be cleaned up by scope leave.
2018-
return args.GetReturnValue().Set(
2019-
v8::Integer::New(env->isolate(), req.result));
2019+
Local<Value> out[] = {
2020+
Integer::New(isolate, req.result), // errno
2021+
FIXED_ONE_BYTE_STRING(isolate, "open"), // syscall
2022+
};
2023+
return args.GetReturnValue().Set(Array::New(isolate, out, arraysize(out)));
20202024
}
20212025
uv_fs_req_cleanup(&req);
20222026

@@ -2036,8 +2040,12 @@ static void ReadFileSync(const FunctionCallbackInfo<Value>& args) {
20362040
if (req.result < 0) {
20372041
FS_SYNC_TRACE_END(read);
20382042
// req will be cleaned up by scope leave.
2043+
Local<Value> out[] = {
2044+
Integer::New(isolate, req.result), // errno
2045+
FIXED_ONE_BYTE_STRING(isolate, "read"), // syscall
2046+
};
20392047
return args.GetReturnValue().Set(
2040-
v8::Integer::New(env->isolate(), req.result));
2048+
Array::New(isolate, out, arraysize(out)));
20412049
}
20422050
uv_fs_req_cleanup(&req);
20432051
if (r <= 0) {

0 commit comments

Comments
 (0)