-
- static handleFileException(
- logPrefix: string,
- fileType: FileType,
- file: string,
- error: NodeJS.ErrnoException,
- params: HandleErrorParams<EmptyObject> = { throwError: true, consoleOut: false }
- ): void {
- const prefix = !Utils.isEmptyString(logPrefix) ? logPrefix + ' ' : '';
- if (error.code === 'ENOENT') {
- if (params?.consoleOut) {
- console.warn(
- chalk.green(prefix) + chalk.yellow(fileType + ' file ' + file + ' not found: '),
- error
- );
- } else {
- logger.warn(prefix + fileType + ' file ' + file + ' not found: %j', error);
- }
- } else if (error.code === 'EEXIST') {
- if (params?.consoleOut) {
- console.warn(
- chalk.green(prefix) + chalk.yellow(fileType + ' file ' + file + ' already exists: '),
- error
- );
- } else {
- logger.warn(prefix + fileType + ' file ' + file + ' already exists: %j', error);
- }
- } else if (error.code === 'EACCES') {
- if (params?.consoleOut) {
- console.warn(
- chalk.green(prefix) + chalk.yellow(fileType + ' file ' + file + ' access denied: '),
- error
- );
- } else {
- logger.warn(prefix + fileType + ' file ' + file + ' access denied: %j', error);
- }
- } else {
- if (params?.consoleOut) {
- console.warn(
- chalk.green(prefix) + chalk.yellow(fileType + ' file ' + file + ' error: '),
- error
- );
- } else {
- logger.warn(prefix + fileType + ' file ' + file + ' error: %j', error);
- }
- if (params?.throwError) {
- throw error;
- }
+): fs.FSWatcher | undefined => {
+ if (Utils.isNotEmptyString(file)) {
+ try {
+ return fs.watch(file, listener);
+ } catch (error) {
+ handleFileException(file, fileType, error as NodeJS.ErrnoException, logPrefix, {
+ throwError: false,
+ });