From 08a6d9effd4e27aa45a04a0624995e618f5f8628 Mon Sep 17 00:00:00 2001 From: eladkeyshawn Date: Tue, 6 Apr 2021 00:18:34 +0300 Subject: [PATCH] util: add getSystemErrorMap() impl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/38101 Fixes: https://github.com/nodejs/node/issues/37951 Reviewed-By: Antoine du Hamel Reviewed-By: Darshan Sen Reviewed-By: Benjamin Gruenbaum Reviewed-By: Juan José Arboleda Reviewed-By: James M Snell --- doc/api/util.md | 19 +++++++++++++++++++ lib/internal/util.js | 12 ++++++++++++ lib/util.js | 2 ++ test/parallel/test-uv-errmap.js | 24 ++++++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 test/parallel/test-uv-errmap.js diff --git a/doc/api/util.md b/doc/api/util.md index ab634380c3c406..e52c54176da014 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -376,6 +376,25 @@ fs.access('file/that/does/not/exist', (err) => { }); ``` +## `util.getSystemErrorMap()` + + +* Returns: {Map} + +Returns a Map of all system error codes available from the Node.js API. +The mapping between error codes and error names is platform-dependent. +See [Common System Errors][] for the names of common errors. + +```js +fs.access('file/that/does/not/exist', (err) => { + const errorMap = util.getSystemErrorMap(); + const name = errorMap.get(err.errno); + console.error(name); // ENOENT +}); +``` + ## `util.inherits(constructor, superConstructor)`