Skip to content

Commit 78c03da

Browse files
committed
Remove output errors to console by default
1 parent 8b51fba commit 78c03da

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

Diff for: CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
```
2222

2323
- Added `resolveSymlinks` option to enable symlink resolving, a symlink resolving is disabled by default
24-
- Rename `NormRule` type into `MatchRule`
24+
- Renamed `NormRule` type into `MatchRule`
2525
- Added `ScanResult` type to define returning type of `scanFs()`
26+
- Removed output errors to console by default
2627

2728
## 3.0.0 (2022-06-09)
2829

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ A value of `options` parameter is a string (which equivalent to `{ basedir: <str
9595
- **onError**
9696

9797
Type: `function(error)` or `null`
98-
Default: `error => console.error('...', error)`
98+
Default: `null`
9999

100-
A handler that is used when an error is occuring during FS scan or file processing. By default errors output in `stderr`, that's can be disabled by passing another function or a falsy value. Errors also can be reached by `errors` field of a result (i.e. `files.errors`).
100+
A handler that is used when an error is occuring during FS scan or file processing. By default nothing happens, but adds to errors `array` which can be reached by `errors` field of a result.
101101

102102
A **rule** is an object with following fields (all are optional):
103103

Diff for: src/index.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,7 @@ export function normalizeOptions(options: Options | string = {}): NormalizedOpti
151151
const resolveSymlinks = Boolean(options.resolveSymlinks);
152152
const generalInclude = new Set(ensureArray(options.include).map(posixNormalize));
153153
const generalExclude = new Set(ensureArray(options.exclude).map(posixNormalize));
154-
const onError =
155-
'onError' in options === false
156-
? (err: Error) => console.error('[@discoveryjs/scan-fs]', err)
157-
: typeof options.onError === 'function'
158-
? options.onError
159-
: () => {};
154+
const onError = typeof options.onError === 'function' ? options.onError : () => {};
160155

161156
const rawRules = ensureArray(options.rules).filter(Boolean);
162157
const onlyRule = rawRules.find((rule) => rule.only);
@@ -325,7 +320,7 @@ export async function scanFs(options?: Options | string): Promise<ScanResult> {
325320
if (extract !== null) {
326321
tasks.push(
327322
fsPromise
328-
.readFile(basedir + relpath, rule.encoding) // TODO: use encoding from rule config
323+
.readFile(basedir + relpath, rule.encoding)
329324
.then((content) => extract(file, content, rule))
330325
.catch((error) => {
331326
errors.push((error = scanError('extract', relpath, error)));

0 commit comments

Comments
 (0)