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:
parent
59041d4f03
commit
2cab121b35
1 changed files with 7 additions and 7 deletions
|
|
@ -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}"));
|
||||
|
|
|
|||
Loading…
Reference in a new issue