Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
10 changes: 9 additions & 1 deletion src/providers/filters/error.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 });

Expand Down
2 changes: 1 addition & 1 deletion src/providers/filters/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/readers/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ export abstract class Reader<T> {
}

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;
}
}
4 changes: 4 additions & 0 deletions src/tests/utils/errno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
14 changes: 14 additions & 0 deletions src/utils/errno.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
});
});
});
4 changes: 4 additions & 0 deletions src/utils/errno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}