fix: fall back to stdlib mimetypes when puremagic returns empty#1391
Open
kostakost2 wants to merge 1 commit intosimonw:mainfrom
Open
fix: fall back to stdlib mimetypes when puremagic returns empty#1391kostakost2 wants to merge 1 commit intosimonw:mainfrom
kostakost2 wants to merge 1 commit intosimonw:mainfrom
Conversation
When puremagic cannot identify a file type it may return an empty string
instead of raising PureError. This empty string was passed through as the
MIME type, causing attachment validation to fail with:
Error: This model does not support attachments of type ''
Fix: treat empty puremagic results the same as PureError. For
mimetype_from_path, additionally fall back to Python's stdlib
mimetypes.guess_type() which handles common extensions (.mp4, .jpg, etc.)
reliably.
Closes simonw#1340
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1340.
When
puremagiccannot identify a file type it may return an empty string instead of raisingPureError. This empty string was passed through as the MIME type, causing attachment validation to fail with:Changes
llm/utils.py:mimetype_from_path(): treat emptypuremagicresults the same asPureError, then fall back to Python'smimetypes.guess_type()which handles common extensions (.mp4, .jpg, etc.) reliablymimetype_from_string(): treat emptypuremagicresults as detection failure (returnsNone)Test plan
test_mimetype_from_path_falls_back_to_stdlib— empty .mp4 file correctly detected asvideo/mp4test_mimetype_from_path_returns_none_for_unknown— truly unknown extension returnsNone🤖 Generated with Claude Code