Przeglądaj źródła

wallet: show error message when image cant load

darkfi 1 rok temu
rodzic
commit
392b9d7f44
1 zmienionych plików z 7 dodań i 3 usunięć
  1. 7 3
      bin/darkwallet/src/ui/image.rs

+ 7 - 3
bin/darkwallet/src/ui/image.rs

@@ -111,11 +111,15 @@ impl Image {
     fn load_texture(&self) -> GfxTextureId {
         let path = self.path.get();
 
-        // TODO we should NOT use unwrap here
+        // TODO we should NOT use panic here
         let data = Arc::new(SyncMutex::new(vec![]));
         let data2 = data.clone();
-        miniquad::fs::load_file(&path, move |res| {
-            *data2.lock().unwrap() = res.unwrap();
+        miniquad::fs::load_file(&path.clone(), move |res| match res {
+            Ok(res) => *data2.lock().unwrap() = res,
+            Err(e) => {
+                error!(target: "ui::image", "Unable to open image: {path}");
+                panic!("Resource not found!");
+            }
         });
         let data = std::mem::take(&mut *data.lock().unwrap());
         let img =