Repository navigation
Empty attachments are a usage error, not a traceback - #1854
Merged
Merged
Conversation
chrikrah
approved these changes
Nov 7, 2026
chrikrah
left a comment
Contributor
There was a problem hiding this comment.
This fixes #1853. After a rebase on main, it can be merged from my side. #1857 landed after your base and also adds tests at the end of tests/test_attachments.py, so that file conflicts. I kept both blocks. Then empty stdin, an empty file and an empty pipe all give the -a usage error, exit 2. The three new tests fail with the old utils.py.
# Python 3.12.3, puremagic 2.2.0; base b9786a2daa, head e91985abbb, main 39d325492b; PYTHONPATH=<exported tree>
printf '' | python -m llm -m nosuchmodel -a - hi
(base) -> puremagic.main.PureValueError: Input was empty (exit 1)
(head) -> Error: Invalid value for '-a' / '--attachment': Could not determine mimetype of stdin (exit 2)
python -m llm -m nosuchmodel -a empty.bin hi (head) -> ... Could not determine mimetype of empty.bin (exit 2)
pytest tests/test_attachments.py -q (base) -> 13 passed
pytest tests/test_attachments.py -q (head) -> 16 passed
pytest tests/test_attachments.py -q (head, utils.py reverted) -> 3 failed, 13 passed
# git merge-tree --write-tree origin/main e91985abbb, conflict resolved by keeping both test blocks
pytest tests/test_attachments.py -q (merged) -> 18 passed
python -m llm -m nosuchmodel -a <(printf '') hi (merged) -> ... Could not determine mimetype of /proc/self/fd/13 (exit 2)
non-blocking: the except in mimetype_from_path has no comment on why ValueError is there. Copy the one from mimetype_from_string?
`llm -a -` with empty stdin, or `-a` with an empty file, crashed with puremagic's "Input was empty": for empty input puremagic raises a ValueError subclass, not PureError, so it got past both mimetype helpers. They now return None for it, and the CLI reports "Could not determine mimetype of ..." as it does for any unrecognised content. Fixes simonw#1853 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
simonw
force-pushed
the
fix/empty-attachment-mimetype
branch
from
November 11, 2026 17:09
e91985a to
cecd06f
Compare
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.
Fixes #1853
printf '' | llm -m mock -a - hi(and-awith an empty file) crashed with puremagic'sPureValueError: Input was empty. For empty input puremagic raises aValueErrorsubclass rather thanPureError(with puremagic 2.2.0, andPureValueErrorisn't exported at the top level), so it got past bothmimetype_from_stringandmimetype_from_path.Both helpers now catch
(puremagic.PureError, ValueError)and returnNone, so the CLI shows its usual usage error:Tests:
test_prompt_attachment_empty[stdin]and[file]: exit code 2, the error message, and the model never calledtest_mimetype_of_empty_content: both helpers returnNonefor empty contentAll three failed before the change with the traceback from the issue. The full suite passes (1401), and
black --check,mypy llm,ruff checkandcog --checkare clean.Prepared with Claude Code.