summaryrefslogtreecommitdiff
path: root/lib/internal/fs
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-04-18 12:25:57 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-04-28 14:46:23 +0800
commit2b24ffae2240163a74ae11e49ee198e98abb07dc (patch)
treef6abfd48eba3b21e722dd96e0ede245d50d28035 /lib/internal/fs
parent31b3dd28429df7ea7ebc84bdfaf8d9eb9e417b41 (diff)
downloadandroid-node-v8-2b24ffae2240163a74ae11e49ee198e98abb07dc.tar.gz
android-node-v8-2b24ffae2240163a74ae11e49ee198e98abb07dc.tar.bz2
android-node-v8-2b24ffae2240163a74ae11e49ee198e98abb07dc.zip
lib: print to stdout/stderr directly instead of using console
This patch adds an internal function that prints to stdout or stderr by directly writing to the known file descriptor, and uses it internally in common cases to avoid the overhead of the console implementation. PR-URL: https://github.com/nodejs/node/pull/27320 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/internal/fs')
-rw-r--r--lib/internal/fs/utils.js22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js
index ca8328f553..dde78654e0 100644
--- a/lib/internal/fs/utils.js
+++ b/lib/internal/fs/utils.js
@@ -12,7 +12,8 @@ const {
ERR_INVALID_OPT_VALUE_ENCODING,
ERR_OUT_OF_RANGE
},
- hideStackFrames
+ hideStackFrames,
+ uvException
} = require('internal/errors');
const {
isUint8Array,
@@ -444,7 +445,26 @@ function warnOnNonPortableTemplate(template) {
}
}
+// This handles errors following the convention of the fs binding.
+function handleErrorFromBinding(ctx) {
+ if (ctx.errno !== undefined) { // libuv error numbers
+ const err = uvException(ctx);
+ // eslint-disable-next-line no-restricted-syntax
+ Error.captureStackTrace(err, handleErrorFromBinding);
+ throw err;
+ }
+ if (ctx.error !== undefined) { // Errors created in C++ land.
+ // TODO(joyeecheung): currently, ctx.error are encoding errors
+ // usually caused by memory problems. We need to figure out proper error
+ // code(s) for this.
+ // eslint-disable-next-line no-restricted-syntax
+ Error.captureStackTrace(ctx.error, handleErrorFromBinding);
+ throw ctx.error;
+ }
+}
+
module.exports = {
+ handleErrorFromBinding,
assertEncoding,
copyObject,
Dirent,