{"record":{"id":"4890b1ab70e62e8d","repo":"moghtech/komodo","slug":"must-attach-either-swarm-or-server","errorCode":null,"errorMessage":"Must attach either swarm or server","messagePattern":"Must attach either swarm or server","errorType":"validation","errorClass":"anyhow::Error","httpStatus":400,"severity":"error","filePath":"client/core/rs/src/entities/mod.rs","lineNumber":1704,"sourceCode":"    ResourceTargetVariant::Alerter => {\n      format!(\"/alerters/{id}\")\n    }\n  };\n  format!(\"{host}{path}\")\n}\n\n#[allow(clippy::large_enum_variant)]\npub enum SwarmOrServer {\n  Swarm(swarm::Swarm),\n  Server(server::Server),\n  None,\n}\n\nimpl SwarmOrServer {\n  pub fn verify_has_target(&self) -> mogh_error::Result<()> {\n    if let Self::None = self {\n      Err(\n        anyhow!(\"Must attach either swarm or server\")\n          .status_code(StatusCode::BAD_REQUEST),\n      )\n    } else {\n      Ok(())\n    }\n  }\n\n  pub fn swarm_id(&self) -> Option<&str> {\n    let Self::Swarm(swarm) = self else {\n      return None;\n    };\n    Some(&swarm.id)\n  }\n\n  pub fn swarm_name(&self) -> Option<&str> {\n    let Self::Swarm(swarm) = self else {\n      return None;\n    };","sourceCodeStart":1686,"sourceCodeEnd":1722,"githubUrl":"https://github.com/moghtech/komodo/blob/780ac68b992094a9fccd5fffb760e0c84fd3c3d1/client/core/rs/src/entities/mod.rs#L1686-L1722","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nlet target = SwarmOrServer::None;\n// after\nlet target = SwarmOrServer::Server(server_id);\ntarget.verify_has_target()?;","handlingStrategy":"validation","validationCode":"target.verify_has_target().context(\"request requires a swarm or server target\")?;","typeGuard":"fn has_target(t: &SwarmOrServer) -> bool { !matches!(t, SwarmOrServer::None) }","tryCatchPattern":"match target.verify_has_target() {\n    Err(e) => return Err(e.context(\"configure a Swarm or Server before calling this API\")),\n    Ok(()) => {},\n}","preventionTips":["Always construct SwarmOrServer via helper constructors, never leave the None default","Call verify_has_target early in request-building code to fail fast"],"tags":["api","validation","komodo"],"backgroundTag":"missing-required-argument","analyzedSha":"780ac68b992094a9fccd5fffb760e0c84fd3c3d1","analyzedAt":"2026-09-08T10:02:44.861Z","contentChangedAt":"2026-09-08T10:02:44.861Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}