Skip to content

Commit 2df27b9

Browse files
nathanwhitbartlomieju
authored andcommitted
fix(ext/node): properly map reparse point error in readlink (#26375)
1 parent ed1b2db commit 2df27b9

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

ext/node/ops/winerror.rs

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub fn op_node_sys_to_uv_error(err: i32) -> String {
6666
ERROR_INVALID_PARAMETER => "EINVAL",
6767
WSAEINVAL => "EINVAL",
6868
WSAEPFNOSUPPORT => "EINVAL",
69+
ERROR_NOT_A_REPARSE_POINT => "EINVAL",
6970
ERROR_BEGINNING_OF_MEDIA => "EIO",
7071
ERROR_BUS_RESET => "EIO",
7172
ERROR_CRC => "EIO",

ext/node/polyfills/_fs/_fs_readlink.ts

+21-12
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44
// deno-lint-ignore-file prefer-primordials
55

66
import { TextEncoder } from "ext:deno_web/08_text_encoding.js";
7-
import {
8-
intoCallbackAPIWithIntercept,
9-
MaybeEmpty,
10-
notImplemented,
11-
} from "ext:deno_node/_utils.ts";
7+
import { MaybeEmpty, notImplemented } from "ext:deno_node/_utils.ts";
128
import { pathFromURL } from "ext:deno_web/00_infra.js";
139
import { promisify } from "ext:deno_node/internal/util.mjs";
10+
import { denoErrorToNodeError } from "ext:deno_node/internal/errors.ts";
1411

1512
type ReadlinkCallback = (
1613
err: MaybeEmpty<Error>,
@@ -69,12 +66,17 @@ export function readlink(
6966

7067
const encoding = getEncoding(optOrCallback);
7168

72-
intoCallbackAPIWithIntercept<string, Uint8Array | string>(
73-
Deno.readLink,
74-
(data: string): string | Uint8Array => maybeEncode(data, encoding),
75-
cb,
76-
path,
77-
);
69+
Deno.readLink(path).then((data: string) => {
70+
const res = maybeEncode(data, encoding);
71+
if (cb) cb(null, res);
72+
}, (err: Error) => {
73+
if (cb) {
74+
(cb as (e: Error) => void)(denoErrorToNodeError(err, {
75+
syscall: "readlink",
76+
path,
77+
}));
78+
}
79+
});
7880
}
7981

8082
export const readlinkPromise = promisify(readlink) as (
@@ -88,5 +90,12 @@ export function readlinkSync(
8890
): string | Uint8Array {
8991
path = path instanceof URL ? pathFromURL(path) : path;
9092

91-
return maybeEncode(Deno.readLinkSync(path), getEncoding(opt));
93+
try {
94+
return maybeEncode(Deno.readLinkSync(path), getEncoding(opt));
95+
} catch (error) {
96+
throw denoErrorToNodeError(error, {
97+
syscall: "readlink",
98+
path,
99+
});
100+
}
92101
}

0 commit comments

Comments
 (0)