{"record":{"id":"1af5f058f9f6c598","repo":"clockworklabs/SpacetimeDB","slug":"environment-publish-failed-with-http","errorCode":null,"errorMessage":"Environment publish failed with HTTP {}","messagePattern":"Environment publish failed with HTTP (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/publish/environment.rs","lineNumber":139,"sourceCode":"    );\n    let metadata: EnvironmentMetadata = response.json().await.context(\"Invalid environment metadata\")?;\n    let schema = EnvironmentSchema::new(metadata.declarations)?;\n    let resolved = resolve(&schema, input, |key| std::env::var_os(key))?;\n    options.validate_values(&resolved.values)?;\n    print!(\"{}\", resolved.display());\n    let request = PublishRequest {\n        module: None,\n        environment: resolved.values,\n        environment_remove: options.remove.clone(),\n        environment_replace: options.replace,\n        expected_module_version: Some(metadata.module_version),\n    };\n    let response = add_auth_header_opt(client.put(url), &auth)\n        .header(reqwest::header::CONTENT_TYPE, CONTENT_TYPE)\n        .body(request.encode()?)\n        .send()\n        .await?;\n    anyhow::ensure!(\n        response.status().is_success(),\n        \"Environment publish failed with HTTP {}\",\n        response.status()\n    );\n    match response\n        .json::<spacetimedb_client_api_messages::name::PublishResult>()\n        .await\n        .map_err(|_| anyhow::anyhow!(\"Invalid publish response\"))?\n    {\n        spacetimedb_client_api_messages::name::PublishResult::Success { database_identity, .. } => {\n            println!(\"Updated environment for database {database_identity}\");\n            Ok(())\n        }\n        spacetimedb_client_api_messages::name::PublishResult::PermissionDenied { .. } => {\n            anyhow::bail!(\"Permission denied publishing environment values\")\n        }\n    }\n}","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/cli/src/subcommands/publish/environment.rs#L121-L157","documentation":"`publish_only` PUTs the encoded environment update to the server and requires a success status. Any non-2xx response — authentication failure, permission denied on the database, schema/validation rejection, server error — aborts with this message including the status code.","triggerScenarios":"PUT of the environment update returns 401/403 (bad token or not the database owner), 4xx validation error (e.g. invalid key/value against the module's declared schema), or 5xx server failure.","commonSituations":"Publishing environment values for a database owned by another identity; supplying values that fail `validate_supplied_values` server-side; token expiry mid-session; transient server outage.","solutions":["Read the HTTP status: 401/403 → `spacetime login` again and confirm you own the database identity.","Verify supplied keys/values match the module's declared environment schema (names, formats).","Retry if the status is 5xx and check server logs/health.","Ensure the database identity used matches the one the module was published under."],"exampleFix":"// before\nspacetime publish -s https://prod.example mydb  # Environment publish failed with HTTP 403 Forbidden\n// after: log in with the owning identity\nspacetime login --server https://prod.example\nspacetime publish -s https://prod.example mydb","handlingStrategy":"try-catch","validationCode":"// pre-check ownership and auth before publishing env values\nspacetime list --server \"$SERVER\" | grep -q \"$DB\" || echo \"database not found/owned by you\"\nspacetime login show --server \"$SERVER\" >/dev/null || spacetime login --server \"$SERVER\"","typeGuard":null,"tryCatchPattern":"// rust\nmatch publish_env().await {\n    Err(e) if e.to_string().contains(\"Environment publish failed with HTTP 40\") => {\n        relogin().await?; publish_env().await\n    }\n    other => other,\n}","preventionTips":["Publish environment values under the same identity that owns the database.","Validate supplied keys/values against the module's declared schema client-side first.","For 5xx statuses, check server health before retrying."],"tags":["http","environment","publish","server-response"],"backgroundTag":"http-error-response","analyzedSha":"eddf9f5014579a50d4b67630e28b6e15cad9c4af","analyzedAt":"2026-09-20T12:15:59.611Z","contentChangedAt":"2026-09-20T12:15:59.611Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}