From 2cab121b359096f0957459dcd0b2a051af76eedd Mon Sep 17 00:00:00 2001 From: iris Date: Sun, 26 Jul 2026 03:22:26 +0200 Subject: [PATCH] fix(dashboard): replace unreachable! with proper 400 in post_pause/post_resume Returning a 400 Bad Request instead of panicking on an invalid ident makes the handlers correct in all codepaths, not just the happy path. --- hive-c0re/src/dashboard/lifecycle_ops.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hive-c0re/src/dashboard/lifecycle_ops.rs b/hive-c0re/src/dashboard/lifecycle_ops.rs index a6c7ce0a..70d4acbf 100644 --- a/hive-c0re/src/dashboard/lifecycle_ops.rs +++ b/hive-c0re/src/dashboard/lifecycle_ops.rs @@ -25,7 +25,7 @@ pub(super) struct GracefulParams { graceful: bool, } -use super::{AppState, error_response, guard_agent_name, strip_container_prefix}; +use super::{AppState, Ident, error_response, guard_agent_name, strip_container_prefix}; use crate::job_queue::{Source, submit}; use crate::{actions, lifecycle}; @@ -153,9 +153,9 @@ pub(super) async fn post_pause( if let Some(reject) = guard_agent_name(&state, &logical).await { return reject; } - // guard_agent_name already validated `logical` as a well-formed Ident. - let Ok(ident) = hive_types::Ident::parse(&logical) else { - unreachable!("guard_agent_name passed an invalid ident"); + let ident = match Ident::parse(&logical) { + Ok(i) => i, + Err(e) => return (StatusCode::BAD_REQUEST, format!("bad agent name: {e}")).into_response(), }; if let Err(e) = crate::coordinator::Coordinator::set_paused(&ident, true) { return error_response(&format!("pause {logical}: {e}")); @@ -176,9 +176,9 @@ pub(super) async fn post_resume( if let Some(reject) = guard_agent_name(&state, &logical).await { return reject; } - // guard_agent_name already validated `logical` as a well-formed Ident. - let Ok(ident) = hive_types::Ident::parse(&logical) else { - unreachable!("guard_agent_name passed an invalid ident"); + let ident = match Ident::parse(&logical) { + Ok(i) => i, + Err(e) => return (StatusCode::BAD_REQUEST, format!("bad agent name: {e}")).into_response(), }; if let Err(e) = crate::coordinator::Coordinator::set_paused(&ident, false) { return error_response(&format!("resume {logical}: {e}"));