Ver código fonte

feat(core): improve tray icon read error messages (#4850)

Lucas Fernandes Nogueira 3 anos atrás
pai
commit
52f0c8bb83
2 arquivos alterados com 11 adições e 6 exclusões
  1. 5 0
      .changes/improve-tray-errors.md
  2. 6 6
      core/tauri-codegen/src/context.rs

+ 5 - 0
.changes/improve-tray-errors.md

@@ -0,0 +1,5 @@
+---
+"tauri-codegen": patch
+---
+
+Improve tray icon read error message.

+ 6 - 6
core/tauri-codegen/src/context.rs

@@ -420,14 +420,14 @@ fn ico_icon<P: AsRef<Path>>(
 
   let path = path.as_ref();
   let bytes = std::fs::read(&path)
-    .unwrap_or_else(|_| panic!("failed to read icon {}", path.display()))
+    .unwrap_or_else(|e| panic!("failed to read icon {}: {}", path.display(), e))
     .to_vec();
   let icon_dir = ico::IconDir::read(std::io::Cursor::new(bytes))
-    .unwrap_or_else(|_| panic!("failed to parse icon {}", path.display()));
+    .unwrap_or_else(|e| panic!("failed to parse icon {}: {}", path.display(), e));
   let entry = &icon_dir.entries()[0];
   let rgba = entry
     .decode()
-    .unwrap_or_else(|_| panic!("failed to decode icon {}", path.display()))
+    .unwrap_or_else(|e| panic!("failed to decode icon {}: {}", path.display(), e))
     .rgba_data()
     .to_vec();
   let width = entry.width();
@@ -459,7 +459,7 @@ fn raw_icon<P: AsRef<Path>>(out_dir: &Path, path: P) -> Result<TokenStream, Embe
 
   let path = path.as_ref();
   let bytes = std::fs::read(&path)
-    .unwrap_or_else(|_| panic!("failed to read icon {}", path.display()))
+    .unwrap_or_else(|e| panic!("failed to read icon {}: {}", path.display(), e))
     .to_vec();
 
   let out_path = out_dir.join(path.file_name().unwrap());
@@ -491,12 +491,12 @@ fn png_icon<P: AsRef<Path>>(
 
   let path = path.as_ref();
   let bytes = std::fs::read(&path)
-    .unwrap_or_else(|_| panic!("failed to read icon {}", path.display()))
+    .unwrap_or_else(|e| panic!("failed to read icon {}: {}", path.display(), e))
     .to_vec();
   let decoder = png::Decoder::new(std::io::Cursor::new(bytes));
   let mut reader = decoder
     .read_info()
-    .unwrap_or_else(|_| panic!("failed to read icon {}", path.display()));
+    .unwrap_or_else(|e| panic!("failed to read icon {}: {}", path.display(), e));
   let mut buffer: Vec<u8> = Vec::new();
   while let Ok(Some(row)) = reader.next_row() {
     buffer.extend(row.data());