From 8d49f504957a00c0f68c7f936b546123aebeb8a8 Mon Sep 17 00:00:00 2001 From: Luca Giannini <68999840+structwafel@users.noreply.github.com> Date: Sat, 22 Feb 2025 15:12:47 +0100 Subject: [PATCH] fix: handle failing icon loading linux gracefully (#193) --- packages/tauri-plugins/jarvis/src/utils/icns.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/tauri-plugins/jarvis/src/utils/icns.rs b/packages/tauri-plugins/jarvis/src/utils/icns.rs index cef887d..1845d30 100644 --- a/packages/tauri-plugins/jarvis/src/utils/icns.rs +++ b/packages/tauri-plugins/jarvis/src/utils/icns.rs @@ -52,10 +52,13 @@ pub fn load_icns(icns_path: &PathBuf) -> anyhow::Result { #[cfg(target_os = "linux")] pub fn load_icon(path: PathBuf) -> tauri::http::Response> { match path.exists() { - true => { - let bytes = std::fs::read(&path).expect("Error reading file"); - tauri::http::Response::builder().body(bytes).unwrap() - } + true => match std::fs::read(&path) { + Ok(bytes) => tauri::http::Response::builder().body(bytes).unwrap(), + Err(err) => tauri::http::Response::builder() + .status(tauri::http::StatusCode::NOT_FOUND) + .body(format!("error loading icon: {:?}", err).as_bytes().to_vec()) + .unwrap(), + }, false => { let res = tauri::http::Response::builder() .status(tauri::http::StatusCode::NOT_FOUND)