The same image-loading error closure is copy-pasted eleven times across two command files, and the copies have started drifting in formatting style.
Evidence
The closure
image::open(path).map_err(|e| anyhow::anyhow!("Failed to load image {:?}: {}", path, e))
appears at src/commands/generate_vlm.rs lines 587, 634, 777, 913, 1014, 1108, 1234, 1303, 1458, 1685 and at src/commands/generate_diffusion.rs:54. The user-facing message is identical at all eleven sites, but the formatting has drifted: most use the {:?}, {} positional style, while generate_vlm.rs:777 uses the inline style:
.map_err(|error| anyhow::anyhow!("Failed to load image {:?}: {error}", path))
and generate_diffusion.rs:54 uses a bare anyhow! import instead of anyhow::anyhow!. Any future change to the message (adding a hint, changing the path formatting) now needs eleven coordinated edits.
Suggested fix
Add one helper, either in generate_vlm.rs or in a shared commands util:
fn open_image(path: &Path) -> anyhow::Result<image::DynamicImage> {
image::open(path).map_err(|e| anyhow::anyhow!("Failed to load image {:?}: {}", path, e))
}
and call it from all eleven sites. Mechanical change, roughly 40 lines net.
Acceptance criteria
The same image-loading error closure is copy-pasted eleven times across two command files, and the copies have started drifting in formatting style.
Evidence
The closure
appears at src/commands/generate_vlm.rs lines 587, 634, 777, 913, 1014, 1108, 1234, 1303, 1458, 1685 and at src/commands/generate_diffusion.rs:54. The user-facing message is identical at all eleven sites, but the formatting has drifted: most use the
{:?}, {}positional style, while generate_vlm.rs:777 uses the inline style:and generate_diffusion.rs:54 uses a bare
anyhow!import instead ofanyhow::anyhow!. Any future change to the message (adding a hint, changing the path formatting) now needs eleven coordinated edits.Suggested fix
Add one helper, either in generate_vlm.rs or in a shared commands util:
and call it from all eleven sites. Mechanical change, roughly 40 lines net.
Acceptance criteria
open_imagehelper exists;grep -rn "Failed to load image" src/commands/matches exactly one definition siteFailed to load image {:?}: {}with the path and the underlying error)cargo buildand existing tests pass unchanged