Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf102a01

Browse files
author
evgeniy.chernomortsev
committed
fix(common): improve error handling in FileTypeValidator
Add warning logs when file-type package fails to load due to ESMimport issues. This helps users debug issues when running testswith Jest without --experimental-vm-modules flag.When loading fails and fallbackToMimetype is enabled, the validatornow correctly falls back to mimetype comparison instead of silentlyreturning false.Closes#15055
1 parent879d370 commitf102a01

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

‎packages/common/pipes/file/file-type.validator.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import{Logger}from'../../services/logger.service';
12
import{FileValidator}from'./file-validator.interface';
23
import{IFile}from'./interfaces';
34
import{loadEsm}from'load-esm';
45

6+
constlogger=newLogger('FileTypeValidator');
7+
58
exporttypeFileTypeValidatorOptions={
69
fileType:string|RegExp;
710

@@ -103,7 +106,27 @@ export class FileTypeValidator extends FileValidator<
103106
return!!file.mimetype.match(this.validationOptions.fileType);
104107
}
105108
returnfalse;
106-
}catch{
109+
}catch(error){
110+
consterrorMessage=
111+
errorinstanceofError ?error.message :String(error);
112+
113+
// Check for common ESM loading issues
114+
if(
115+
errorMessage.includes('ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING')||
116+
errorMessage.includes('Cannot find module')||
117+
errorMessage.includes('ERR_MODULE_NOT_FOUND')
118+
){
119+
logger.warn(
120+
`Failed to load "file-type" package for magic number validation. `+
121+
`If using Jest, run with NODE_OPTIONS="--experimental-vm-modules". `+
122+
`Error:${errorMessage}`,
123+
);
124+
}
125+
126+
// Fallback to mimetype if enabled
127+
if(this.validationOptions.fallbackToMimetype){
128+
return!!file.mimetype.match(this.validationOptions.fileType);
129+
}
107130
returnfalse;
108131
}
109132
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp