From ab3c9d41e483e5a7e6a326c66af7052a51301f91 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 5 Oct 2023 23:57:20 +0530 Subject: fix(ext/node): implement uv.errname (#20785) Fixes https://github.com/denoland/deno/issues/20617 --- cli/tests/unit_node/process_test.ts | 13 +++++++++++++ ext/node/polyfills/internal_binding/uv.ts | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/cli/tests/unit_node/process_test.ts b/cli/tests/unit_node/process_test.ts index bcb7a9767..78c5fcc97 100644 --- a/cli/tests/unit_node/process_test.ts +++ b/cli/tests/unit_node/process_test.ts @@ -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"); + }, +}); diff --git a/ext/node/polyfills/internal_binding/uv.ts b/ext/node/polyfills/internal_binding/uv.ts index c08d44565..3cb145d28 100644 --- a/ext/node/polyfills/internal_binding/uv.ts +++ b/ext/node/polyfills/internal_binding/uv.ts @@ -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})`; +} -- cgit v1.2.3