summaryrefslogtreecommitdiff
path: root/src/index.rs
diff options
context:
space:
mode:
authorNaz <ndpm13@ch-naseem.com>2025-08-06 16:32:48 +0100
committerNaz <ndpm13@ch-naseem.com>2025-08-06 16:32:48 +0100
commitd22690ad41e90c5f34c587e75994e865c2395912 (patch)
tree2a2a007b57741452453f292f664ee2ac4af9646d /src/index.rs
parentb3f2823d433e76fd011f2f372495abddf03a484a (diff)
✨feat: improve error handling for missing apps
Diffstat (limited to 'src/index.rs')
-rw-r--r--src/index.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/index.rs b/src/index.rs
index 8f2521a..35bfadf 100644
--- a/src/index.rs
+++ b/src/index.rs
@@ -1,6 +1,6 @@
use tokio::fs;
-use crate::{AppImage, Result, index_dir};
+use crate::{AppImage, Error, Result, index_dir};
#[derive(Debug, Default)]
pub struct Index {}
@@ -11,7 +11,13 @@ impl Index {
}
pub async fn get(&self, appname: &str) -> Result<AppImage> {
let index_file_path = index_dir()?.join(format!("{appname}.json"));
- let index_file_content = fs::read_to_string(&index_file_path).await?;
+ let index_file_content = fs::read_to_string(&index_file_path).await.map_err(|e| {
+ if e.kind() == std::io::ErrorKind::NotFound {
+ Error::NotFound(appname.to_string())
+ } else {
+ Error::from(e)
+ }
+ })?;
let appimage: AppImage = serde_json::from_str(&index_file_content)?;
Ok(appimage)