Skip to content

fix(common): improve error handling in FileTypeValidator#16100

Merged
kamilmysliwiec merged 3 commits into
nestjs:masterfrom
malkovitc:fix/file-type-validator-esm-error
Dec 21, 2025
Merged

fix(common): improve error handling in FileTypeValidator#16100
kamilmysliwiec merged 3 commits into
nestjs:masterfrom
malkovitc:fix/file-type-validator-esm-error

Conversation

@malkovitc

Copy link
Copy Markdown

PR Checklist

PR Type

  • Bugfix

What is the current behavior?

Issue Number: #15055

FileTypeValidator silently returns false when ESM loading fails (e.g., in Jest without --experimental-vm-modules), making it difficult to diagnose why file validation is failing.

What is the new behavior?

  • Added warning log when file-type package fails to load due to ESM issues
  • Log message includes helpful hint about Jest configuration
  • Added fallback to mimetype check when fallbackToMimetype option is enabled and loading fails

Does this PR introduce a breaking change?

  • Yes
  • No

Add warning logs when file-type package fails to load due to ESM
import issues. This helps users debug issues when running tests
with Jest without --experimental-vm-modules flag.

When loading fails and fallbackToMimetype is enabled, the validator
now correctly falls back to mimetype comparison instead of silently
returning false.

Closes nestjs#15055
Comment thread packages/common/pipes/file/file-type.validator.ts Outdated
@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build c7ef8c4e-aa6e-4c83-9dd5-2308d11676ed

Details

  • 5 of 7 (71.43%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.02%) to 89.709%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/common/pipes/file/file-type.validator.ts 5 7 71.43%
Totals Coverage Status
Change from base Build c12f7b6d-24bb-42a9-81aa-f1e9cb8e5c7e: -0.02%
Covered Lines: 7436
Relevant Lines: 8289

💛 - Coveralls

@kamilmysliwiec kamilmysliwiec merged commit f58d86d into nestjs:master Dec 21, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants