Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const {
ObjectDefineProperties,
ObjectDefineProperty,
Promise,
PromisePrototypeThen,
PromiseResolve,
ReflectApply,
SafeMap,
Expand Down Expand Up @@ -3171,15 +3172,11 @@ function glob(pattern, options, callback) {
callback = makeCallback(callback);

const Glob = lazyGlob();
// TODO: Use iterator helpers when available
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this TODO was added in 151d365 and already resolved in 090add7

(async () => {
try {
const res = await ArrayFromAsync(new Glob(pattern, options).glob());
callback(null, res);
} catch (err) {
callback(err);
}
})();
PromisePrototypeThen(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the catch?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the second argument to then():

node/lib/fs.js

Line 3178 in 8b29b14

callback,

ArrayFromAsync(new Glob(pattern, options).glob()),
(res) => callback(null, res),
callback,
);
}

function globSync(pattern, options) {
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-fs-glob-throw.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { mustCall } from '../common/index.mjs';
import { glob } from 'node:fs';
import process from 'node:process';
import { strictEqual } from 'node:assert';

// One uncaught error is expected
process.on('uncaughtException', mustCall((err) => {
strictEqual(err.message, 'blep');
}));

{
// Test that if callback throws, it's not getting called again
glob('a/b/c', mustCall(() => {
throw new Error('blep');
}));
}
Loading