You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a filter callback supplied to fs.walk throws an error, the process terminates abnormally, without a chance for the caller to catch the error.
Steps to reproduce
Example 1
// example-1.jsconstfsWalk=require('@nodelib/fs.walk');try{fsWalk.walk('.',{entryFilter(){thrownewError('Something is broken');}},error=>{if(error){console.log('Error caught in callback');}});}catch(error){console.log('Error caught outside callback');}
Example 2
// example-2.mjsimport{promisify}from'node:util';import{walk}from'@nodelib/fs.walk';constwalkAsync=promisify(walk);try{awaitwalkAsync('.',{deepFilter(){thrownewError('Something is broken');}});}catch(error){console.log('Error caught. All is good.');}
Expected behavior
In both examples above, the error thrown in the filter (entryFilter or deepFilter), should be caught and execution should continue normally.
Actually, both examples will crash the process with an uncaught exception in a different call context, e.g.
$ node example-2.mjsfile:///.../example-2.mjs:10 throw new Error('Something is broken'); ^Error: Something is broken at deepFilter (file:///.../example-2.mjs:10:23) at Object.isAppliedFilter (.../node_modules/@nodelib/fs.walk/out/readers/common.js:12:31) at AsyncReader._handleEntry (.../node_modules/@nodelib/fs.walk/out/readers/async.js:89:50) at .../node_modules/@nodelib/fs.walk/out/readers/async.js:65:22 at callSuccessCallback (.../node_modules/@nodelib/fs.scandir/out/providers/async.js:103:5) at .../node_modules/@nodelib/fs.scandir/out/providers/async.js:29:13 at node:fs:193:23 at node:internal/util:522:12 at getDirents (node:internal/fs/utils:286:7) at req.oncomplete (node:fs:1480:7)
I can fix the problem in fs.scandir by ensuring that the failure callback is always called if the success callback throws an error (these are actually the same function with different parameters).
Describe the bug
When a filter callback supplied to
fs.walk
throws an error, the process terminates abnormally, without a chance for the caller to catch the error.Steps to reproduce
Example 1
Example 2
Expected behavior
In both examples above, the error thrown in the filter (
entryFilter
ordeepFilter
), should be caught and execution should continue normally.Actually, both examples will crash the process with an uncaught exception in a different call context, e.g.
Environment
fs.walk
2.0.0,fs.scandir
3.0.0The text was updated successfully, but these errors were encountered: