diff --git a/README.md b/README.md index e584c83d..9ee16556 100644 --- a/README.md +++ b/README.md @@ -393,7 +393,7 @@ fg.globSync('*.json', { ignore: ['package-lock.json'] }); // ['package.json'] * Type: `boolean` * Default: `false` -By default this package suppress only `ENOENT` errors. Set to `true` to suppress any error. +By default this package suppress only `ENOENT` and `ENOTDIR` errors. Set to `true` to suppress any error. > :book: Can be useful when the directory has entries with a special level of access. diff --git a/src/providers/filters/error.spec.ts b/src/providers/filters/error.spec.ts index 2079b55a..70a0c701 100644 --- a/src/providers/filters/error.spec.ts +++ b/src/providers/filters/error.spec.ts @@ -6,8 +6,8 @@ import Settings from '../../settings'; import * as tests from '../../tests'; import ErrorFilter from './error'; -import type { ErrorFilterFunction } from '../../types'; import type { Options } from '../../settings'; +import type { ErrorFilterFunction } from '../../types'; function getErrorFilterInstance(options?: Options): ErrorFilter { const settings = new Settings(options); @@ -37,6 +37,14 @@ describe('Providers → Filters → Error', () => { assert.ok(actual); }); + it('should return true for ENOTDIR error', () => { + const filter = getFilter(); + + const actual = filter(tests.errno.getEnotdir()); + + assert.ok(actual); + }); + it('should return true for EPERM error when the `suppressErrors` options is enabled', () => { const filter = getFilter({ suppressErrors: true }); diff --git a/src/providers/filters/error.ts b/src/providers/filters/error.ts index 9dba5fae..9c5f3107 100644 --- a/src/providers/filters/error.ts +++ b/src/providers/filters/error.ts @@ -15,6 +15,6 @@ export default class ErrorFilter { } #isNonFatalError(error: ErrnoException): boolean { - return utils.errno.isEnoentCodeError(error) || this.#settings.suppressErrors; + return utils.errno.isEnoentCodeError(error) || utils.errno.isEnotdirCodeError(error) || this.#settings.suppressErrors; } } diff --git a/src/readers/reader.ts b/src/readers/reader.ts index 8dd7a41c..0479b291 100644 --- a/src/readers/reader.ts +++ b/src/readers/reader.ts @@ -44,6 +44,6 @@ export abstract class Reader { } protected _isFatalError(error: ErrnoException): boolean { - return !utils.errno.isEnoentCodeError(error) && !this.#settings.suppressErrors; + return !utils.errno.isEnoentCodeError(error) && !utils.errno.isEnotdirCodeError(error) && !this.#settings.suppressErrors; } } diff --git a/src/tests/utils/errno.ts b/src/tests/utils/errno.ts index 901933b7..19a0bc19 100644 --- a/src/tests/utils/errno.ts +++ b/src/tests/utils/errno.ts @@ -11,6 +11,10 @@ export function getEnoent(): ErrnoException { return new SystemError('ENOENT', 'no such file or directory'); } +export function getEnotdir(): ErrnoException { + return new SystemError('ENOTDIR', 'not a directory'); +} + export function getEperm(): ErrnoException { return new SystemError('EPERM', 'operation not permitted'); } diff --git a/src/utils/errno.spec.ts b/src/utils/errno.spec.ts index 2c9937c7..03726a2f 100644 --- a/src/utils/errno.spec.ts +++ b/src/utils/errno.spec.ts @@ -15,4 +15,18 @@ describe('Utils → Errno', () => { assert.ok(!util.isEnoentCodeError(tests.errno.getEperm())); }); }); + + describe('.isEnotdirCodeError', () => { + it('should return true for ENOTDIR error', () => { + assert.ok(util.isEnotdirCodeError(tests.errno.getEnotdir())); + }); + + it('should return false for ENOENT error', () => { + assert.ok(!util.isEnotdirCodeError(tests.errno.getEnoent())); + }); + + it('should return false for EPERM error', () => { + assert.ok(!util.isEnotdirCodeError(tests.errno.getEperm())); + }); + }); }); diff --git a/src/utils/errno.ts b/src/utils/errno.ts index 59c09f77..88c1ba5c 100644 --- a/src/utils/errno.ts +++ b/src/utils/errno.ts @@ -3,3 +3,7 @@ import type { ErrnoException } from '../types'; export function isEnoentCodeError(error: ErrnoException): boolean { return error.code === 'ENOENT'; } + +export function isEnotdirCodeError(error: ErrnoException): boolean { + return error.code === 'ENOTDIR'; +}