-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Closed
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.
Description
What is the problem this feature will solve?
Take following minimal test case:
import fs from 'node:fs/promises';
async function b( ) { return await fs.readFile( 'inexistent' ); }
async function a( ) { return await b( ); }
await a( );the output will be:
internalBinding('errors').triggerUncaughtException(
^
[Error: ENOENT: no such file or directory, open 'inexistent'] {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: 'inexistent'
}
Node.js v20.8.0
so no hint where.
What is the feature you are proposing to solve the problem?
I used to wrap all fs call to something like this:
import fs from 'node:fs/promises';
async function myread( filename )
{
try { return await fs.readFile( filename ); }
catch( e ) { throw new Error( 'cannot read "' + filename + '"' ); }
}
async function b( ) { return await myread( 'inexistent' ); }
async function a( ) { return await b( ); }
await a( );So the error stack becomes:
file:///home/axel/xtest2/x2.mjs:6
catch( e ) { throw new Error( 'cannot read "' + filename + '"' ); }
^
Error: cannot read "inexistent"
at myread (file:///home/axel/xtest2/x2.mjs:6:21)
at async b (file:///home/axel/xtest2/x2.mjs:8:30)
at async a (file:///home/axel/xtest2/x2.mjs:9:30)
at async file:///home/axel/xtest2/x2.mjs:10:1
Suggestion: IMO it would be beneficial for node to make these more userfriendly/useful backtraces by default without having to wrap all fs calls by the user?
What alternatives have you considered?
explained above, wrap the fs calls with try/catch blocks all myself, it's very possible, likely someone wrote a npm package anyway, likely several, but IMO this is one of the things the core should come with making the entry easier for new people.
Metadata
Metadata
Assignees
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.