tauri-apps/tauri · error
failed to parse icon
Error message
failed to parse icon {}: {} What it means
EmbeddedImage::new_ico reads an .ico file and parses it with the `ico` crate during macro expansion. If ico::IconDir::read fails — the file is not a valid ICO container or is truncated/corrupt — the macro panics with this message, naming the icon path and the underlying parse error.
Solutions
- Regenerate the .ico with a proper converter (e.g. `ImageMagick: magick icon.png -define icon:auto-resize=32,16 icon.ico`)
- Verify the file starts with the ICO magic bytes 00 00 01 00
- Re-download or restore the icon from version control
- Use a PNG icon with ImageFormat::Png instead of ICO
Example fix
// before cp icon.png icon.ico // invalid: renamed PNG // after magick icon.png -define icon:auto-resize=256,128,64,48,32,16 icon.ico
Defensive patterns
Strategy: validation
Validate before calling
with open('icon.ico','rb') as f:
if f.read(4) != b'\x00\x00\x01\x00':
raise SystemExit('not a valid ICO file') Prevention
- Generate ICOs with a real converter, never by renaming PNGs
- Check icon files into git without LFS smudge issues, or verify checksums
- Keep icons as standard multi-size 32-bit BMP-frame ICOs
- Add a pre-commit hook validating icon magic bytes
When it happens
Trigger: Passing an `icon` path whose bytes are not a valid ICO (e.g. a PNG renamed to .ico with a header the parser rejects, or a truncated download) into tauri::icon! / EmbeddedAssets icon handling.
Common situations: Renaming a PNG to .ico instead of converting; icons corrupted by git LFS smudge failure; partially downloaded icon files; icons generated by tools producing unsupported ICO variants.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18).
Data as JSON: /api/errors/1b5b0cea1841297a.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tauri-codegen/src/image.rs:55
}
}
/// Cache the icon without any manipulation.
pub fn new_raw(root: &TokenStream, icon: &Path) -> EmbeddedAssetsResult<Self> {
let buf = Self::open(icon);
Cached::try_from(buf).map(|cache| Self {
cache,
root: root.clone(),
format: IconFormat::Raw,
})
}
/// Cache an ICO icon as RGBA data, see [`ImageFormat::Image`].
pub fn new_ico(root: &TokenStream, icon: &Path) -> EmbeddedAssetsResult<Self> {
let buf = Self::open(icon);
let icon_dir = ico::IconDir::read(Cursor::new(&buf))
.unwrap_or_else(|e| panic!("failed to parse icon {}: {}", icon.display(), e));
let entry = &icon_dir.entries()[0];
let rgba = entry
.decode()
.unwrap_or_else(|e| panic!("failed to decode icon {}: {}", icon.display(), e))
.rgba_data()
.to_vec();
Cached::try_from(rgba).map(|cache| Self {
cache,
root: root.clone(),
format: IconFormat::Image {
width: entry.width(),
height: entry.height(),
},
})
}
View on GitHub (pinned to 460ec35447)