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.
This commit is contained in:
iris 2026-07-26 03:22:26 +02:00 committed by mara
commit 2cab121b35

View file

@ -25,7 +25,7 @@ pub(super) struct GracefulParams {
graceful: bool, 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::job_queue::{Source, submit};
use crate::{actions, lifecycle}; use crate::{actions, lifecycle};
@ -153,9 +153,9 @@ pub(super) async fn post_pause(
if let Some(reject) = guard_agent_name(&state, &logical).await { if let Some(reject) = guard_agent_name(&state, &logical).await {
return reject; return reject;
} }
// guard_agent_name already validated `logical` as a well-formed Ident. let ident = match Ident::parse(&logical) {
let Ok(ident) = hive_types::Ident::parse(&logical) else { Ok(i) => i,
unreachable!("guard_agent_name passed an invalid ident"); Err(e) => return (StatusCode::BAD_REQUEST, format!("bad agent name: {e}")).into_response(),
}; };
if let Err(e) = crate::coordinator::Coordinator::set_paused(&ident, true) { if let Err(e) = crate::coordinator::Coordinator::set_paused(&ident, true) {
return error_response(&format!("pause {logical}: {e}")); 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 { if let Some(reject) = guard_agent_name(&state, &logical).await {
return reject; return reject;
} }
// guard_agent_name already validated `logical` as a well-formed Ident. let ident = match Ident::parse(&logical) {
let Ok(ident) = hive_types::Ident::parse(&logical) else { Ok(i) => i,
unreachable!("guard_agent_name passed an invalid ident"); Err(e) => return (StatusCode::BAD_REQUEST, format!("bad agent name: {e}")).into_response(),
}; };
if let Err(e) = crate::coordinator::Coordinator::set_paused(&ident, false) { if let Err(e) = crate::coordinator::Coordinator::set_paused(&ident, false) {
return error_response(&format!("resume {logical}: {e}")); return error_response(&format!("resume {logical}: {e}"));