summaryrefslogtreecommitdiff
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
parentb3f2823d433e76fd011f2f372495abddf03a484a (diff)
✨feat: improve error handling for missing apps
-rw-r--r--src/error.rs5
-rw-r--r--src/index.rs10
2 files changed, 9 insertions, 6 deletions
diff --git a/src/error.rs b/src/error.rs
index 25fc685..f946f58 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -31,10 +31,7 @@ pub enum Error {
impl core::fmt::Display for Error {
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::result::Result<(), std::fmt::Error> {
match self {
- Error::Io(e) => match e.kind() {
- std::io::ErrorKind::NotFound => write!(fmt, "File or directory not found"),
- _ => write!(fmt, "IO error: {e}"),
- },
+ Error::Io(e) => write!(fmt, "{e}"),
Error::NotFound(name) => write!(fmt, "Application '{name}' not found"),
Error::Json(e) => write!(fmt, "JSON error: {e}"),
Error::Http(e) => write!(fmt, "HTTP error: {e}"),
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)