aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sys.zig2
-rw-r--r--test/js/node/fs/fs.test.ts21
2 files changed, 22 insertions, 1 deletions
diff --git a/src/sys.zig b/src/sys.zig
index 2890deba3..d07641030 100644
--- a/src/sys.zig
+++ b/src/sys.zig
@@ -258,7 +258,7 @@ pub fn getErrno(rc: anytype) bun.C.E {
return switch (Type) {
comptime_int, usize => std.os.linux.getErrno(@as(usize, rc)),
- i32, c_int, isize => std.os.linux.getErrno(@as(usize, @bitCast(@as(isize, rc)))),
+ i32, c_int, isize => std.os.errno(rc),
else => @compileError("Not implemented yet for type " ++ @typeName(Type)),
};
}
diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts
index cdd14bb01..2f898a2ea 100644
--- a/test/js/node/fs/fs.test.ts
+++ b/test/js/node/fs/fs.test.ts
@@ -18,6 +18,7 @@ import fs, {
rmSync,
rmdir,
rmdirSync,
+ renameSync,
createReadStream,
createWriteStream,
promises,
@@ -2020,3 +2021,23 @@ it("BigIntStats", () => {
expect(withBigInt.ctime.getTime()).toEqual(withoutBigInt.ctime.getTime());
expect(withBigInt.birthtime.getTime()).toEqual(withoutBigInt.birthtime.getTime());
});
+
+it("test syscall errno, issue#4198", () => {
+ const path = `${tmpdir()}/non-existent-${Date.now()}.txt`;
+ expect(() => openSync(path, "r")).toThrow("No such file or directory");
+ expect(() => readSync(2147483640, Buffer.alloc(0))).toThrow("Bad file number");
+ expect(() => readlinkSync(path)).toThrow("No such file or directory");
+ expect(() => realpathSync(path)).toThrow("No such file or directory");
+ expect(() => readFileSync(path)).toThrow("No such file or directory");
+ expect(() => renameSync(path, `${path}.2`)).toThrow("No such file or directory");
+ expect(() => statSync(path)).toThrow("No such file or directory");
+ expect(() => unlinkSync(path)).toThrow("No such file or directory");
+ expect(() => rmSync(path)).toThrow("No such file or directory");
+ expect(() => rmdirSync(path)).toThrow("No such file or directory");
+ expect(() => closeSync(2147483640)).toThrow("Bad file number");
+
+ mkdirSync(path);
+ expect(() => mkdirSync(path)).toThrow("File or folder exists");
+ expect(() => unlinkSync(path)).toThrow("Is a directory");
+ rmdirSync(path);
+});