{"record":{"id":"e049e749e4ed7fb2","repo":"clockworklabs/SpacetimeDB","slug":"environment-value-does-not-match-its-declared-enum","errorCode":null,"errorMessage":"environment value does not match its declared enum: {}","messagePattern":"environment value does not match its declared enum: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/bindings-macro/src/environment/value.rs","lineNumber":89,"sourceCode":"    let constraint = match values.as_slice() {\n        [value] => quote!(::spacetimedb::spacetimedb_lib::environment::EnvVarType::StringLiteral(#value.into())),\n        values => quote!(::spacetimedb::spacetimedb_lib::environment::EnvVarType::Union(\n            ::std::vec![#(#values.into()),*]\n        )),\n    };\n    let ident = &item.ident;\n    Ok(quote! {\n        impl ::spacetimedb::rt::EnvironmentValue for #ident {\n            const OPTIONAL: bool = false;\n\n            fn constraint() -> ::spacetimedb::spacetimedb_lib::environment::EnvVarType {\n                #constraint\n            }\n\n            fn from_environment(value: ::std::option::Option<::std::string::String>, key: &str) -> Self {\n                match value.as_deref() {\n                    #(::std::option::Option::Some(#values) => Self::#variants,)*\n                    ::std::option::Option::Some(_) => ::core::panic!(\"environment value does not match its declared enum: {}\", key),\n                    ::std::option::Option::None => ::core::panic!(\"required environment key is missing: {}\", key),\n                }\n            }\n        }\n        impl ::spacetimedb::rt::RequiredEnvironmentValue for #ident {}\n    })\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn rejects_invalid_enum_shapes_mappings_and_limits() {\n        for input in [\n            quote!(\n                struct Value;\n            ),","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/bindings-macro/src/environment/value.rs#L71-L107","documentation":"This macro-generated from_environment implementation panics at runtime when the actual environment value is Some(s) but s does not match any of the enum's declared variant strings. The type's accepted strings are an exact, closed set, so any other value is unrecoverable for that attribute.","triggerScenarios":"A process environment variable is set to a value that is not one of the enum's exact variant strings (case-sensitive) when the derived type is parsed via accepts_exact_strings_and_ordinary_enum_attributes.","commonSituations":"Setting MODE=production when the enum only accepts 'Production'; typos, trailing whitespace, or lowercase values in .env files; renamed enum variants after a version upgrade while the host still exports the old value.","solutions":["Set the environment variable to exactly one of the declared variant strings (case-sensitive)","Update the enum to include the value being supplied","Trim whitespace and fix casing in the .env file or process environment"],"exampleFix":"// before\nMODE=production  # enum variant is 'Production'\n// after\nMODE=Production","handlingStrategy":"try-catch","validationCode":"const ALLOWED_MODES = [\"Production\", \"Staging\", \"Dev\"];\nlet mode = std::env::var(\"MODE\").unwrap_or_default();\nassert!(ALLOWED_MODES.contains(&mode.as_str()), \"MODE={mode} not in {ALLOWED_MODES:?}\");","typeGuard":null,"tryCatchPattern":"// panic! is not catchable; validate before the library parses the value:\nmatch std::env::var(\"MODE\") {\n  Ok(v) if matches!(v.as_str(), \"Production\" | \"Staging\" | \"Dev\") => {}\n  Ok(v) => eprintln!(\"MODE={v} not allowed\"),\n  Err(_) => eprintln!(\"MODE unset\"),\n}","preventionTips":["Keep an allowlist of exact accepted strings next to the deployment config","Trim whitespace in .env files and avoid case drift","Update deployment env in lockstep with enum variant renames"],"tags":["environment","rust","macro","panic","enum"],"backgroundTag":"invalid-env-var-value","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"}