Skip to content

Commit c308a87

Browse files
authored
Fixes edge-app delete (#235)
* fix: Handle missing edge app in get_app The `get_app` function panicked when trying to access the first element of the returned app list if the list was empty (e.g., app not found). This commit adds a check for an empty list in `get_app` and returns a `ResourceNotFound` error in that case. It also adds the `ResourceNotFound` variant to the `CommandError` enum. * Bumps deps * run clippy * Rolls back Cargo.lock * Backward compatability * Fixes compatability issues * Rename ResourceNotFound to AppNotFound
1 parent 28d18b8 commit c308a87

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/api/edge_app/app.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ impl Api {
7373
&format!("v4/edge-apps?select=name&id=eq.{}", app_id),
7474
)?;
7575

76-
Ok(serde_json::from_value::<Vec<EdgeApp>>(response)?[0].clone())
76+
let apps = serde_json::from_value::<Vec<EdgeApp>>(response)?;
77+
if apps.is_empty() {
78+
Err(CommandError::AppNotFound(format!(
79+
"Edge app with ID '{}' not found.",
80+
app_id
81+
)))
82+
} else {
83+
Ok(apps[0].clone())
84+
}
7785
}
7886

7987
pub fn copy_assets(&self, payload: Value) -> Result<Vec<String>, CommandError> {

src/commands/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ pub enum CommandError {
130130
PathIsNotDirError(String),
131131
#[error("Missing installation id in the instance file")]
132132
MissingInstallationId,
133+
#[error("App not found: {0}")]
134+
AppNotFound(String),
133135
}
134136

135137
pub fn get(

0 commit comments

Comments
 (0)