moghtech/komodo · error · anyhow::Error
Must attach either swarm or server
Error message
Must attach either swarm or server
What it means
SwarmOrServer::verify_has_target ensures a request is attached to either a Swarm or a standalone Server target. If the value is SwarmOrServer::None (no target attached), it returns a 400 BAD_REQUEST error. Many Komodo API calls require a concrete deployment target to execute against.
Solutions
- Attach a target before the call: set SwarmOrServer::Server(server_id) or SwarmOrServer::Swarm(swarm_id)
- Call verify_has_target() early in your flow to fail fast with a clear 400 instead of mid-operation
- Review request-builder code paths that may leave the value as its None default
Example fix
// before let target = SwarmOrServer::None; // after let target = SwarmOrServer::Server(server_id); target.verify_has_target()?;
Defensive patterns
Strategy: validation
Validate before calling
target.verify_has_target().context("request requires a swarm or server target")?; Type guard
fn has_target(t: &SwarmOrServer) -> bool { !matches!(t, SwarmOrServer::None) } Try / catch
match target.verify_has_target() {
Err(e) => return Err(e.context("configure a Swarm or Server before calling this API")),
Ok(()) => {},
} Prevention
- Always construct SwarmOrServer via helper constructors, never leave the None default
- Call verify_has_target early in request-building code to fail fast
When it happens
Trigger: Calling an API action that requires a target while the client's SwarmOrServer is set to None — e.g. building a request without calling the server/swarm attachment helpers, or defaulting the enum to None.
Common situations: Forgetting to configure the target when constructing a periphery/server-scoped request; copying client setup code that omits target attachment; logic that clears the target on some code path.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
AI-assisted analysis of moghtech/komodo@780ac68b99 (2026-09-08).
Data as JSON: /api/errors/4890b1ab70e62e8d.
Report an issue: GitHub.
Appendix: source
Thrown at client/core/rs/src/entities/mod.rs:1704
ResourceTargetVariant::Alerter => {
format!("/alerters/{id}")
}
};
format!("{host}{path}")
}
#[allow(clippy::large_enum_variant)]
pub enum SwarmOrServer {
Swarm(swarm::Swarm),
Server(server::Server),
None,
}
impl SwarmOrServer {
pub fn verify_has_target(&self) -> mogh_error::Result<()> {
if let Self::None = self {
Err(
anyhow!("Must attach either swarm or server")
.status_code(StatusCode::BAD_REQUEST),
)
} else {
Ok(())
}
}
pub fn swarm_id(&self) -> Option<&str> {
let Self::Swarm(swarm) = self else {
return None;
};
Some(&swarm.id)
}
pub fn swarm_name(&self) -> Option<&str> {
let Self::Swarm(swarm) = self else {
return None;
};View on GitHub (pinned to 780ac68b99)