summaryrefslogtreecommitdiff
path: root/lib/internal/fs/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/internal/fs/utils.js')
-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,