{"record":{"id":"07bb35b6b102c458","repo":"tauri-apps/tauri","slug":"creating-icon","errorCode":null,"errorMessage":"creating icon","messagePattern":"creating icon","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri/src/app.rs","lineNumber":2632,"sourceCode":"    },\n    RuntimeRunEvent::WebviewEvent { label, event } => RunEvent::WebviewEvent {\n      label,\n      event: event.into(),\n    },\n    RuntimeRunEvent::Ready => {\n      // set the app icon in development\n      #[cfg(all(dev, target_os = \"macos\"))]\n      {\n        use objc2::{AllocAnyThread, MainThreadMarker};\n        use objc2_app_kit::{NSApplication, NSImage};\n        use objc2_foundation::NSData;\n\n        if let Some(icon) = app_handle.manager.app_icon.clone() {\n          // TODO: Enable this check.\n          let mtm = unsafe { MainThreadMarker::new_unchecked() };\n          let app = NSApplication::sharedApplication(mtm);\n          let data = NSData::with_bytes(&icon);\n          let app_icon = NSImage::initWithData(NSImage::alloc(), &data).expect(\"creating icon\");\n          unsafe { app.setApplicationIconImage(Some(&app_icon)) };\n        }\n      }\n      RunEvent::Ready\n    }\n    RuntimeRunEvent::Resumed => RunEvent::Resumed,\n    RuntimeRunEvent::MainEventsCleared => RunEvent::MainEventsCleared,\n    RuntimeRunEvent::UserEvent(t) => {\n      match t {\n        #[cfg(desktop)]\n        EventLoopMessage::MenuEvent(ref e) => {\n          for listener in &*app_handle\n            .manager\n            .menu\n            .global_event_listeners\n            .lock()\n            .unwrap()\n          {","sourceCodeStart":2614,"sourceCodeEnd":2650,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri/src/app.rs#L2614-L2650","documentation":"Runtime panic on macOS when the app tries to set the dock/window application icon: NSImage::initWithData fails to decode the app icon bytes (manager.app_icon) into an NSImage. The expect(\"creating icon\") fires on RunEvent::MainEventsCleared-style handling in the Tauri builder's macOS run loop, aborting the process.","triggerScenarios":"app_handle.manager.app_icon contains bytes that Cocoa cannot decode into an NSImage: invalid or truncated PNG/ICNS data, an unsupported image format, or corrupt icon data produced upstream during context creation.","commonSituations":"A corrupted or non-image bundle icon file referenced in tauri.conf.json, a custom icon set programmatically with invalid bytes, macOS APIs failing on headless/CI environments, or regression after changing icon configuration.","solutions":["Verify the icon configured in tauri.conf.json (bundle > icon) is a valid, decodable image (e.g. re-export the .icns/.png)","Regenerate icons with `tauri icon` from a clean 1024x1024 source PNG","Check for macOS runtime environment issues (CI/headless) where NSApplication/NSImage may not initialize","If setting the icon programmatically, validate the byte data decodes before passing it to NSImage"],"exampleFix":"// before\nlet app_icon = NSImage::initWithData(NSImage::alloc(), &data).expect(\"creating icon\");\n// after\nif let Some(app_icon) = unsafe { NSImage::initWithData(NSImage::alloc(), &data) } {\n    unsafe { app.setApplicationIconImage(Some(&app_icon)) };\n} else {\n    eprintln!(\"failed to decode application icon data\");\n}","handlingStrategy":"try-catch","validationCode":"if let Some(icon) = &app_handle.manager.app_icon {\n    assert!(image::load_from_memory(icon).is_ok(), \"app icon bytes are not a decodable image\");\n}","typeGuard":"fn is_valid_image(data: &[u8]) -> bool {\n    data.starts_with(&[0x89, b'P', b'N', b'G']) || data.starts_with(b\"icns\")\n}","tryCatchPattern":"match unsafe { NSImage::initWithData(NSImage::alloc(), &data) } {\n    Some(img) => unsafe { app.setApplicationIconImage(Some(&img)) },\n    None => eprintln!(\"skipping app icon: invalid image data\"),\n}","preventionTips":["Regenerate icons with `tauri icon` after changing source art","Keep the configured icon file a valid PNG/ICNS","Avoid running GUI icon code in headless CI"],"tags":["macos","icon","nssize","runtime","image-decode"],"backgroundTag":"invalid-argument-value","analyzedSha":"460ec35447493200d64290dd7f015d5a91d0fd58","analyzedAt":"2026-09-18T23:55:51.277Z","contentChangedAt":"2026-09-18T23:55:51.277Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}