{"record":{"id":"e87f43269f30163c","repo":"clockworklabs/SpacetimeDB","slug":"server-already-configured-for-host-host","errorCode":null,"errorMessage":"Server already configured for host: {host}","messagePattern":"Server already configured for host: (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/config.rs","lineNumber":243,"sourceCode":"    ) -> anyhow::Result<()> {\n        if let Some(nickname) = &nickname\n            && let Ok(cfg) = self.find_server(nickname)\n        {\n            anyhow::bail!(\n                \"Server nickname {} already in use: {}://{}\",\n                nickname,\n                cfg.protocol,\n                cfg.host,\n            );\n        }\n\n        if let Ok(cfg) = self.find_server(&host) {\n            if let Some(nick) = &cfg.nickname\n                && nick == &host\n            {\n                anyhow::bail!(\"Server host name is ambiguous with existing server nickname: {nick}\");\n            }\n            anyhow::bail!(\"Server already configured for host: {host}\");\n        }\n\n        self.server_configs.push(ServerConfig {\n            nickname,\n            host,\n            protocol,\n            ecdsa_public_key,\n        });\n        Ok(())\n    }\n\n    fn host(&self, server: &str) -> anyhow::Result<&str> {\n        self.find_server(server)\n            .map(|cfg| cfg.host.as_ref())\n            .with_context(|| format!(\"Cannot find hostname for unknown server: {server}\"))\n    }\n\n    fn default_host(&self) -> anyhow::Result<&str> {","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/cli/src/config.rs#L225-L261","documentation":"`Config::add_server` (backing `spacetime server add`) refuses to register a server whose host string is already present in the saved CLI configuration. Each host may be configured only once; the check runs after a nickname-ambiguity check, so a duplicate host fails even with a distinct nickname.","triggerScenarios":"Running `spacetime server add <host> ...` (or calling Config::add_server) with a host that `find_server` already resolves to an existing entry.","commonSituations":"Re-running provisioning scripts that add unconditionally; re-adding a server after reinstall while the CLI config file still holds it; adding the same local or maincloud host twice.","solutions":["Remove the existing entry first: `spacetime server remove <existing-name-or-host>`","Edit the existing entry instead: `spacetime server edit <server> ...`","If a genuinely different server shares the host, distinguish it by port or scheme in the host string"],"exampleFix":"# before\nspacetime server add http://localhost:3000 mylocal\n# error: Server already configured for host: http://localhost:3000\n\n# after\nspacetime server remove mylocal\nspacetime server add http://localhost:3000 mylocal","handlingStrategy":"validation","validationCode":"// before adding, check the host is not already configured\nif config.find_server(&host).is_ok() {\n    eprintln!(\"server for {host} already exists; edit or remove it first\");\n} else {\n    config.add_server(nickname, host, protocol, key)?;\n}","typeGuard":null,"tryCatchPattern":"Match the anyhow error message for 'Server already configured for host' and branch to a remove-then-add or edit flow instead of failing the script.","preventionTips":["Make provisioning scripts idempotent: check-before-add or remove-then-add","Use one canonical host string (scheme + port) across all machines and scripts"],"tags":["cli","config","server","duplicate-entry"],"backgroundTag":"duplicate-config-entry","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}