Skip to content

Commit e04c8a4

Browse files
jasnelltargos
authored andcommitted
fs: propagate abortsignal reason in new AbortSignal constructors
Signed-off-by: James M Snell <[email protected]> PR-URL: #41008 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent fa5ac5a commit e04c8a4

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

lib/fs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ function readFileAfterStat(err, stats) {
359359

360360
function checkAborted(signal, callback) {
361361
if (signal?.aborted) {
362-
callback(new AbortError());
362+
callback(new AbortError(undefined, { cause: signal?.reason }));
363363
return true;
364364
}
365365
return false;
@@ -2104,7 +2104,7 @@ function lutimesSync(path, atime, mtime) {
21042104

21052105
function writeAll(fd, isUserFd, buffer, offset, length, signal, callback) {
21062106
if (signal?.aborted) {
2107-
const abortError = new AbortError();
2107+
const abortError = new AbortError(undefined, { cause: signal?.reason });
21082108
if (isUserFd) {
21092109
callback(abortError);
21102110
} else {

lib/internal/fs/promises.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ async function fsCall(fn, handle, ...args) {
324324

325325
function checkAborted(signal) {
326326
if (signal?.aborted)
327-
throw new AbortError();
327+
throw new AbortError(undefined, { cause: signal?.reason });
328328
}
329329

330330
async function writeFileHandle(filehandle, data, signal, encoding) {

lib/internal/fs/read_file_context.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ class ReadFileContext {
8888
let length;
8989

9090
if (this.signal?.aborted) {
91-
return this.close(new AbortError());
91+
return this.close(
92+
new AbortError(undefined, { cause: this.signal?.reason }));
9293
}
9394
if (this.size === 0) {
9495
buffer = Buffer.allocUnsafeSlow(kReadFileUnknownBufferLength);

lib/internal/fs/watchers.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,13 @@ async function* watch(filename, options = {}) {
317317
}
318318

319319
if (signal?.aborted)
320-
throw new AbortError();
320+
throw new AbortError(undefined, { cause: signal?.reason });
321321

322322
const handle = new FSEvent();
323323
let { promise, resolve, reject } = createDeferredPromise();
324324
const oncancel = () => {
325325
handle.close();
326-
reject(new AbortError());
326+
reject(new AbortError(undefined, { cause: signal?.reason }));
327327
};
328328

329329
try {
@@ -362,7 +362,7 @@ async function* watch(filename, options = {}) {
362362
yield await promise;
363363
({ promise, resolve, reject } = createDeferredPromise());
364364
}
365-
throw new AbortError();
365+
throw new AbortError(undefined, { cause: signal?.reason });
366366
} finally {
367367
handle.close();
368368
signal?.removeEventListener('abort', oncancel);

0 commit comments

Comments
 (0)