Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: pass syscall on fs.readFileSync fail operation #48815

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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