Hmbown/CodeWhale · error
expected UnsupportedFormat for
Error message
expected UnsupportedFormat for {name}, got {other:?} What it means
Test assertion in rejects_a_real_image_in_an_unsupported_format_by_name: encode_image_bytes was expected to return ImageAttachError::UnsupportedFormat for the given magic bytes (BMP/TIFF/SVG/PDF fixtures), but returned a different error variant. This fires when format detection misclassifies a rejected-by-name format — e.g. reporting a size or decode error instead of UnsupportedFormat with the detected format name.
Solutions
- Inspect which error variant encode_image_bytes actually returned for the failing fixture
- Verify the magic-byte sniffing order detects BMP ('BM'), TIFF ('II*'/'MM*'), SVG ('<svg'), and PDF ('%PDF-') before falling back to decode attempts
- Ensure unsupported-format detection runs by name/magic bytes prior to any pixel decoding
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at crates/tui/src/image_attach/tests.rs:194 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15).
Data as JSON: /api/errors/abaf0e2d25a045e2.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/image_attach/tests.rs:194
at_limit.resize(MAX_IMAGE_BYTES, 0);
assert!(encode_image_bytes(&at_limit, "edge.png").is_ok());
}
#[test]
fn rejects_a_real_image_in_an_unsupported_format_by_name() {
for (bytes, name) in [
(b"BM\x00\x00\x00\x00".as_slice(), "BMP"),
(b"II\x2a\x00extra".as_slice(), "TIFF"),
(b"MM\x00\x2aextra".as_slice(), "TIFF"),
(b"<svg xmlns=".as_slice(), "SVG"),
(b"%PDF-1.7".as_slice(), "PDF"),
] {
let error = encode_image_bytes(bytes, "f").expect_err("must reject");
match error {
ImageAttachError::UnsupportedFormat { detected, .. } => {
assert_eq!(detected, name);
}
other => panic!("expected UnsupportedFormat for {name}, got {other:?}"),
}
}
}
#[test]
fn rejects_a_file_that_is_not_an_image_at_all() {
let error = encode_image_bytes(b"#!/bin/sh\necho hi\n", "script.png").expect_err("must reject");
assert!(
matches!(error, ImageAttachError::NotAnImage { .. }),
"got {error:?}"
);
}
#[test]
fn rejects_an_empty_file() {
let error = encode_image_bytes(b"", "empty.png").expect_err("must reject");
assert!(
matches!(error, ImageAttachError::Empty { .. }),View on GitHub (pinned to 433685b202)