tauri-apps/tauri · error
Could not get icon filename
Error message
Could not get icon filename
What it means
When creating the .icns for a macOS bundle, if an icon file already has an .icns extension the bundler copies it into the output under its own file name. file_name() returns None for paths that are a filesystem root or end with '..' or '.', so the expect fires only for a degenerate icon path.
Source
Thrown at crates/tauri-bundler/src/bundle/macos/icon.rs:32
process::Command,
};
use image::GenericImageView;
// Given a list of icon files, try to produce an ICNS file in the out_dir
// and return the path to it. Returns `Ok(None)` if no usable icons
// were provided.
pub fn create_icns_file(out_dir: &Path, settings: &Settings) -> crate::Result<Option<PathBuf>> {
if settings.icon_files().count() == 0 {
return Ok(None);
}
// If one of the icon files is already an ICNS file, just use that.
for icon_path in settings.icon_files() {
let icon_path = icon_path?;
if icon_path.extension() == Some(OsStr::new("icns")) {
let mut dest_path = out_dir.to_path_buf();
dest_path.push(icon_path.file_name().expect("Could not get icon filename"));
fs_utils::copy_file(&icon_path, &dest_path)?;
return Ok(Some(dest_path));
}
}
// Otherwise, read available images and pack them into a new ICNS file.
let mut family = icns::IconFamily::new();
fn add_icon_to_family(
icon: image::DynamicImage,
density: u32,
family: &mut icns::IconFamily,
) -> io::Result<()> {
// Try to add this image to the icon family. Ignore images whose sizes
// don't map to any ICNS icon type; print warnings and skip images that
// fail to encode.
match icns::IconType::from_pixel_size_and_density(icon.width(), icon.height(), density) {
Some(icon_type) => {View on GitHub (pinned to 52e4b6e71d)
Solutions
- Fix the offending bundle.icon entry to point at a real file, e.g. icons/AppIcon.icns
- Audit the icon list: every entry must end in an actual file name with an image/icns extension
- Prefer regenerating the icon list with tauri icon instead of hand-maintaining it
Example fix
// tauri.conf.json — before "icon": ["icons/", ".."] // after "icon": ["icons/32x32.png", "icons/128x128.png", "icons/icon.icns"]
Defensive patterns
Strategy: validation
Validate before calling
// validate bundle.icon entries before building
const last = (p) => p.split('/').pop() ?? '';
const bad = config.bundle.icon.filter((p) => ['', '.', '..'].includes(last(p)));
if (bad.length) throw new Error(`icon paths without a file name: ${bad.join(', ')}`); Type guard
const hasIconFileName = (p) => { const seg = p.split('/').pop() ?? ''; return seg.length > 0 && seg !== '.' && seg !== '..'; }; Prevention
- Lint bundle.icon so every entry ends in a real file name with an image/icns extension
- Generate icon lists with tauri icon instead of hand-writing them
- Fail builds on empty variable interpolation in generated tauri.conf.json
When it happens
Trigger: A bundle.icon entry in tauri.conf.json that resolves to a path with no final file-name component (e.g. '..', '.', or a root) while being treated as an .icns source during tauri build on macOS.
Common situations: Script- or template-generated tauri.conf.json where a variable interpolation is empty and collapses an icon path to a directory-like value; hand-edited typos in the icon list.
Related errors
- No matching IconType
- unsupported ColorType: {:?}
- couldn't find a square icon to use as AppImage icon
- Failed to chmod script
- failed to extract external binary filename
AI-assisted analysis of tauri-apps/tauri@52e4b6e71d (2026-08-20).
Data as JSON: /api/errors/dd65c1e5a690fb09.
Report an issue: GitHub.