Skip to content

Commit

Permalink
fixup! fs: aggregate errors in fsPromises to avoid error swallowing
Browse files Browse the repository at this point in the history
  • Loading branch information
Linkgoron committed Apr 16, 2021
1 parent cd8ac99 commit 55961b8
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
PromisePrototypeFinally,
PromisePrototypeThen,
PromiseResolve,
PromiseReject,
SafeArrayIterator,
Symbol,
Uint8Array,
Expand Down Expand Up @@ -252,24 +253,16 @@ class FileHandle extends EventEmitterMixin(JSTransferable) {
}

async function handleFdClose(fileOpPromise, closeFunc) {
let opError;
try {
return await fileOpPromise;
} catch (err) {
opError = err;
throw err;
} finally {
try {
await closeFunc();
} catch (closeError) {
if (!opError) {
// eslint-disable-next-line no-unsafe-finally
throw closeError;
}
// eslint-disable-next-line no-unsafe-finally
throw aggregateTwoErrors(closeError, opError);
}
}
return PromisePrototypeThen(
fileOpPromise,
(result) => PromisePrototypeThen(closeFunc(), () => result),
(opError) =>
PromisePrototypeThen(
closeFunc(),
() => PromiseReject(opError),
(closeError) => PromiseReject(aggregateTwoErrors(closeError, opError))
)
);
}

async function fsCall(fn, handle, ...args) {
Expand Down

0 comments on commit 55961b8

Please sign in to comment.