1
1
import * as fs from 'node:fs' ;
2
2
3
- import type { FileSystemAdapter , Pattern } from './types' ;
3
+ import type { ErrnoException , FileSystemAdapter , Pattern } from './types' ;
4
4
5
5
export const DEFAULT_FILE_SYSTEM_ADAPTER : FileSystemAdapter = {
6
6
lstat : fs . lstat ,
@@ -125,6 +125,12 @@ export interface Options {
125
125
* @default false
126
126
*/
127
127
suppressErrors ?: boolean ;
128
+ /**
129
+ * Callback for user-defined error handling. Ignored if `suppressErrors` is `true`.
130
+ *
131
+ * @default false
132
+ */
133
+ errorHandler ?: ( error : Error ) => void ;
128
134
/**
129
135
* Throw an error when symbolic link is broken if `true` or safely
130
136
* return `lstat` call if `false`.
@@ -166,6 +172,7 @@ export default class Settings {
166
172
public readonly onlyFiles : boolean ;
167
173
public readonly stats : boolean ;
168
174
public readonly suppressErrors : boolean ;
175
+ public readonly errorHandler : ( ( error : ErrnoException ) => void ) | undefined ;
169
176
public readonly throwErrorOnBrokenSymbolicLink : boolean ;
170
177
public readonly unique : boolean ;
171
178
public readonly signal ?: AbortSignal ;
@@ -190,7 +197,9 @@ export default class Settings {
190
197
this . onlyFiles = options . onlyFiles ?? true ;
191
198
this . stats = options . stats ?? false ;
192
199
this . suppressErrors = options . suppressErrors ?? false ;
193
- this . throwErrorOnBrokenSymbolicLink = options . throwErrorOnBrokenSymbolicLink ?? false ;
200
+ this . errorHandler = options . errorHandler ?? undefined ;
201
+ this . throwErrorOnBrokenSymbolicLink =
202
+ options . throwErrorOnBrokenSymbolicLink ?? false ;
194
203
this . unique = options . unique ?? true ;
195
204
this . signal = options . signal ;
196
205
0 commit comments