Skip to content

Commit 339eb10

Browse files
authored
src: pass syscall on fs.readFileSync fail operation
PR-URL: #48815 Reviewed-By: Debadree Chatterjee <debadree333@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 6515b3b commit 339eb10

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
@@ -1961,6 +1961,7 @@ static inline Maybe<void> CheckOpenPermissions(Environment* env,
19611961

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

19651966
CHECK_GE(args.Length(), 2);
19661967

@@ -1980,8 +1981,11 @@ static void ReadFileSync(const FunctionCallbackInfo<Value>& args) {
19801981
FS_SYNC_TRACE_END(open);
19811982
if (req.result < 0) {
19821983
// req will be cleaned up by scope leave.
1983-
return args.GetReturnValue().Set(
1984-
v8::Integer::New(env->isolate(), req.result));
1984+
Local<Value> out[] = {
1985+
Integer::New(isolate, req.result), // errno
1986+
FIXED_ONE_BYTE_STRING(isolate, "open"), // syscall
1987+
};
1988+
return args.GetReturnValue().Set(Array::New(isolate, out, arraysize(out)));
19851989
}
19861990
uv_fs_req_cleanup(&req);
19871991

@@ -2001,8 +2005,12 @@ static void ReadFileSync(const FunctionCallbackInfo<Value>& args) {
20012005
if (req.result < 0) {
20022006
FS_SYNC_TRACE_END(read);
20032007
// req will be cleaned up by scope leave.
2008+
Local<Value> out[] = {
2009+
Integer::New(isolate, req.result), // errno
2010+
FIXED_ONE_BYTE_STRING(isolate, "read"), // syscall
2011+
};
20042012
return args.GetReturnValue().Set(
2005-
v8::Integer::New(env->isolate(), req.result));
2013+
Array::New(isolate, out, arraysize(out)));
20062014
}
20072015
uv_fs_req_cleanup(&req);
20082016
if (r <= 0) {

0 commit comments

Comments
 (0)