diff options
author | Schwarzkopf Balázs <schwarzkopfb@icloud.com> | 2020-09-22 22:07:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-22 16:07:35 -0400 |
commit | f601721851bdd64ee5b40bd3d408df063691b425 (patch) | |
tree | 2b226b6080b152cb967a15af4ca0f6ac35bf014f /std/node/util.ts | |
parent | dd1cd4d95237359acd822143265d7d2365bf928c (diff) |
feat(std/node): implement getSystemErrorName() (#7624)
Diffstat (limited to 'std/node/util.ts')
-rw-r--r-- | std/node/util.ts | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/std/node/util.ts b/std/node/util.ts index 27aa5a12b..076a5b830 100644 --- a/std/node/util.ts +++ b/std/node/util.ts @@ -1,10 +1,16 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. export { promisify } from "./_util/_util_promisify.ts"; export { callbackify } from "./_util/_util_callbackify.ts"; +import { codes, errorMap } from "./_errors.ts"; import * as types from "./_util/_util_types.ts"; - export { types }; +const NumberIsSafeInteger = Number.isSafeInteger; +const { + ERR_OUT_OF_RANGE, + ERR_INVALID_ARG_TYPE, +} = codes; + const DEFAULT_INSPECT_OPTIONS = { showHidden: false, depth: 2, @@ -90,6 +96,16 @@ export function isPrimitive(value: unknown): boolean { ); } +export function getSystemErrorName(code: number): string | undefined { + if (typeof code !== "number") { + throw new ERR_INVALID_ARG_TYPE("err", "number", code); + } + if (code >= 0 || !NumberIsSafeInteger(code)) { + throw new ERR_OUT_OF_RANGE("err", "a negative integer", code); + } + return errorMap.get(code)?.[0]; +} + import { _TextDecoder, _TextEncoder } from "./_utils.ts"; /** The global TextDecoder */ |