summaryrefslogtreecommitdiff
path: root/doc/api/util.md
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-01-17 03:21:16 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-01-20 08:51:47 +0800
commit4af1bba6d0f1da1b4d444ef3a936e2ef2c639a1e (patch)
treeae8a75b9ac85984da88ee4af569215b94befd1b5 /doc/api/util.md
parentcbd634947d3aa308266ac6192a5af0a30445a449 (diff)
downloadandroid-node-v8-4af1bba6d0f1da1b4d444ef3a936e2ef2c639a1e.tar.gz
android-node-v8-4af1bba6d0f1da1b4d444ef3a936e2ef2c639a1e.tar.bz2
android-node-v8-4af1bba6d0f1da1b4d444ef3a936e2ef2c639a1e.zip
util: implement util.getSystemErrorName()
Reimplement uv.errname() as internal/util.getSystemErrorName() to avoid the memory leaks caused by unknown error codes and avoid calling into C++ for the error names. Also expose it as a public API for external use. PR-URL: https://github.com/nodejs/node/pull/18186 Refs: http://docs.libuv.org/en/v1.x/errors.html#c.uv_err_name Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'doc/api/util.md')
-rw-r--r--doc/api/util.md20
1 files changed, 20 insertions, 0 deletions
diff --git a/doc/api/util.md b/doc/api/util.md
index 68f8487b1b..c9ce952af3 100644
--- a/doc/api/util.md
+++ b/doc/api/util.md
@@ -257,6 +257,25 @@ intended as a debugging tool. Some input values can have a significant
performance overhead that can block the event loop. Use this function
with care and never in a hot code path.
+## util.getSystemErrorName(err)
+<!-- YAML
+added: REPLACEME
+-->
+
+* `err` {number}
+* Returns: {string}
+
+Returns the string name for a numeric error code that comes from a 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 name = util.getSystemErrorName(err.errno);
+ console.error(name); // ENOENT
+});
+```
+
## util.inherits(constructor, superConstructor)
<!-- YAML
added: v0.3.0
@@ -1362,6 +1381,7 @@ Deprecated predecessor of `console.log`.
[Customizing `util.inspect` colors]: #util_customizing_util_inspect_colors
[Internationalization]: intl.html
[WHATWG Encoding Standard]: https://encoding.spec.whatwg.org/
+[Common System Errors]: errors.html#errors_common_system_errors
[constructor]: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/constructor
[list of deprecated APIS]: deprecations.html#deprecations_list_of_deprecated_apis
[semantically incompatible]: https://github.com/nodejs/node/issues/4179