{"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":null,"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/524b4487d949b61a07d4f39c862d1290259dfd20/crates/cli/src/config.rs#L225-L261","documentation":"Thrown by Config::add_server (the code behind `spacetime server add`) when a server configuration already exists for the given host. The CLI keeps a list of server_configs and enforces one entry per host so that name lookups stay unambiguous; just above this check it also rejects a new host equal to an existing server's nickname. The config persists in the CLI's TOML config file, so the conflict survives across invocations.","triggerScenarios":"Calling `spacetime server add <name> <protocol>://<host>` (or add_server programmatically) when find_server(&host) already resolves to an entry in the saved config. Typically: running the add command a second time with the same URL/host, or adding the same host under a different nickname/protocol.","commonSituations":"Setup or CI scripts that run `spacetime server add` unconditionally on every run; re-adding mainnet/testnet/localhost after switching or restoring a config file; onboarding docs that say 'add the server' without an idempotency check.","solutions":["Run `spacetime server list` to confirm the host is already configured, then reuse that entry (e.g. `spacetime server set-default <name>`) instead of adding again","If the existing entry is stale or wrong, remove/edit it via the `spacetime server` subcommands so the host becomes free, then re-run add","Make provisioning scripts idempotent: grep `spacetime server list` for the host before calling add"],"exampleFix":"# before (fails on the second run)\nspacetime server add http://localhost:3000 local --default\n\n# after (idempotent setup)\nspacetime server list | grep -q localhost:3000 || \\\n  spacetime server add http://localhost:3000 local --default","handlingStrategy":"validation","validationCode":"#!/usr/bin/env bash\n# Before provisioning, confirm the host is not already configured\nHOST='localhost:3000'\nif ! spacetime server list | grep -q \"$HOST\"; then\n  spacetime server add \"http://$HOST\" local --default\nfi","typeGuard":null,"tryCatchPattern":"match config.add_server(nickname, host, protocol, key) {\n    Ok(()) => {}\n    Err(e) if e.to_string().starts_with(\"Server already configured for host\") => {\n        // idempotent provisioning: treat as success\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep `spacetime server add` calls guarded by a `spacetime server list` check in every script that can run twice","Adopt the habit of naming servers by environment and never re-adding the same host under a new nickname"],"tags":["spacetimedb","cli","server-config","duplicate-entry"],"backgroundTag":"duplicate-config-entry","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}