Skip to content

Commit 285635d

Browse files
authored
fix(ext/node): map ERROR_INVALID_NAME to ENOENT on windows (#26475)
In libuv on windows, `ERROR_INVALID_NAME` is mapped to `ENOENT`, but it is mapped to `EINVAL` in our compat implementation, which causes the issue #24899. ref: https://github.com/libuv/libuv/blob/d4ab6fbba4669935a6bc23645372dfe4ac29ab39/src/win/error.c#L138 closes #24899 closes #26411 closes #23635 closes #21165 closes #19067
1 parent 5e020eb commit 285635d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

ext/node/ops/winerror.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn op_node_sys_to_uv_error(err: i32) -> String {
6262
WSAEHOSTUNREACH => "EHOSTUNREACH",
6363
ERROR_INSUFFICIENT_BUFFER => "EINVAL",
6464
ERROR_INVALID_DATA => "EINVAL",
65-
ERROR_INVALID_NAME => "EINVAL",
65+
ERROR_INVALID_NAME => "ENOENT",
6666
ERROR_INVALID_PARAMETER => "EINVAL",
6767
WSAEINVAL => "EINVAL",
6868
WSAEPFNOSUPPORT => "EINVAL",

tests/unit_node/fs_test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,14 @@ Deno.test("[node/fs] copyFile COPYFILE_EXCL works", async () => {
233233
copyFileSync(src, dest2, fsPromiseConstants.COPYFILE_EXCL)
234234
);
235235
});
236+
237+
Deno.test("[node/fs] statSync throws ENOENT for invalid path containing colon in it", () => {
238+
// deno-lint-ignore no-explicit-any
239+
const err: any = assertThrows(() => {
240+
// Note: Deno.stat throws ERROR_INVALID_NAME (os error 123) instead of
241+
// ERROR_FILE_NOT_FOUND (os error 2) on windows. This case checks that
242+
// ERROR_INVALID_NAME is mapped to ENOENT correctly on node compat layer.
243+
statSync("jsr:@std/assert");
244+
});
245+
assertEquals(err.code, "ENOENT");
246+
});

0 commit comments

Comments
 (0)