Skip to content

Commit b5726c5

Browse files
committed
fs: restore stack traces of fs/promises stat permission errors
Since stat() started going through raceWithSignal(), permission errors from fsPromises.stat() have had no stack frames. The binding rejects them right away, and raceWithSignal() returned that promise from an async function without awaiting it, so nothing was awaiting it yet when the stack was captured. Return the promise as is when there is no signal, so stat() awaits it directly again. Refs: #63143 Signed-off-by: vedchaudhari <vedc2853@gmail.com>
1 parent d3c4048 commit b5726c5

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎lib/internal/fs/promises.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,8 +1218,12 @@ function rejectWithReason(signal, reject) {
12181218
};
12191219
}
12201220

1221-
async function raceWithSignal(opPromise, signal) {
1221+
function raceWithSignal(opPromise, signal) {
12221222
if (!signal) return opPromise;
1223+
return raceWithAbortSignal(opPromise, signal);
1224+
}
1225+
1226+
async function raceWithAbortSignal(opPromise, signal) {
12231227
const { promise: abortPromise, reject } = PromiseWithResolvers();
12241228
// eslint-disable-next-line no-unused-vars
12251229
using _ = EventEmitter.addAbortListener(signal,

‎test/parallel/test-permission-fs-promises-stack-trace.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,21 @@ const { status, stderr } = spawnSync(
1616
'-e',
1717
`
1818
const assert = require('assert');
19-
const { readFile, writeFile, appendFile } = require('fs/promises');
19+
const { readFile, writeFile, appendFile, stat } = require('fs/promises');
2020
const target = ${JSON.stringify(tmpdir.resolve('file'))};
2121
2222
function readCaller() { return readFile(target); }
2323
function writeCaller() { return writeFile(target, 'data'); }
2424
function appendCaller() { return appendFile(target, 'data'); }
2525
async function awaitAppendCaller() { await appendFile(target, 'data'); }
26+
async function awaitStatCaller() { await stat(target); }
2627
2728
const cases = [
2829
[readCaller, /at readCaller /],
2930
[writeCaller, /at writeCaller /],
3031
[appendCaller, /at appendCaller /],
3132
[awaitAppendCaller, /at awaitAppendCaller /],
33+
[awaitStatCaller, /at async awaitStatCaller /],
3234
];
3335
let checked = 0;
3436
for (const [caller, stack] of cases) {

0 commit comments

Comments
 (0)