Skip to content

Commit

Permalink
fix(ext/node): implement uv.errname (#20785)
Browse files Browse the repository at this point in the history
Fixes #20617
  • Loading branch information
littledivy authored and bartlomieju committed Oct 12, 2023
1 parent 0fb5d2e commit e377c17
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cli/tests/unit_node/process_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,3 +786,16 @@ Deno.test({
worker.terminate();
},
});

Deno.test({
name: "process.binding('uv').errname",
ignore: Deno.build.os === "windows",
fn() {
// @ts-ignore: untyped internal binding, not actually supposed to be
// used by userland modules in Node.js
const uv = process.binding("uv");
assert(uv.errname);
assert(typeof uv.errname === "function");
assertEquals(uv.errname(-1), "EPERM");
},
});
8 changes: 8 additions & 0 deletions ext/node/polyfills/internal_binding/uv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,11 @@ export const UV_EINVAL = codeMap.get("EINVAL")!;
export const UV_ENOENT = codeMap.get("ENOENT");
export const UV_ENOTSOCK = codeMap.get("ENOTSOCK")!;
export const UV_UNKNOWN = codeMap.get("UNKNOWN")!;

export function errname(errno: number): string {
const err = errorMap.get(errno);
if (err) {
return err[0];
}
return `UNKNOWN (${errno})`;
}

0 comments on commit e377c17

Please sign in to comment.