{"record":{"id":"c962bb41723e8268","repo":"rustfs/rustfs","slug":"failed-to-parse-environment-variable-0-1","errorCode":null,"errorMessage":"Failed to parse environment variable {0}: {1}","messagePattern":"Failed to parse environment variable (.+?): (.+?)","errorType":"exception","errorClass":"ConfigError","httpStatus":null,"severity":"error","filePath":"crates/trusted-proxies/src/error/config.rs","lineNumber":27,"sourceCode":"// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//! Configuration error types for the trusted proxy system.\n\nuse std::net::AddrParseError;\n\n/// Errors related to application configuration.\n#[derive(Debug, thiserror::Error)]\npub enum ConfigError {\n    /// Required environment variable is missing.\n    #[error(\"Missing environment variable: {0}\")]\n    MissingEnvVar(String),\n\n    /// Environment variable exists but could not be parsed.\n    #[error(\"Failed to parse environment variable {0}: {1}\")]\n    EnvParseError(String, String),\n\n    /// A configuration value is logically invalid.\n    #[error(\"Invalid configuration value for {0}: {1}\")]\n    InvalidValue(String, String),\n\n    /// An IP address or CIDR range is malformed.\n    #[error(\"Invalid IP address or network: {0}\")]\n    InvalidIp(String),\n\n    /// Configuration failed overall validation.\n    #[error(\"Configuration validation failed: {0}\")]\n    ValidationFailed(String),\n\n    /// Two or more configuration settings are in conflict.\n    #[error(\"Configuration conflict: {0}\")]\n    Conflict(String),\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/rustfs/rustfs/blob/35af688cd9d41b4346fbe27dcf7250ba72046c1f/crates/trusted-proxies/src/error/config.rs#L9-L45","documentation":"ConfigError::EnvParseError(name, value) reports an environment variable that exists but whose value cannot be parsed into the expected type; the message carries both the variable name and the raw value. It is built by the ConfigError::env_parse_error(key, value) constructor on strict parse paths.","triggerScenarios":"A strictly-parsed numeric or boolean variable receives a malformed value - for example RUSTFS_TRUSTED_PROXY_MAX_HOPS=many, a boolean var set to yes instead of true/1, or a numeric var containing trailing whitespace or a unit.","commonSituations":"Values written by hand into .env files with quotes, spaces or units; copy-paste between shells that mangle quoting; booleans given as on/off/yes instead of true/false; decimal separators from locale-formatted numbers.","solutions":["Fix the value to the documented format for that variable (the error message shows both name and the exact bad value)","For booleans use true/false (or 1/0) as documented; for integers use plain ASCII digits without units or separators","Add a startup lint that pre-parses all typed RUSTFS_* variables and reports offenders in one pass"],"exampleFix":"# before\nRUSTFS_TRUSTED_PROXY_MAX_HOPS=\"10 hops\"\nerror: Failed to parse environment variable RUSTFS_TRUSTED_PROXY_MAX_HOPS: 10 hops\n\n# after\nRUSTFS_TRUSTED_PROXY_MAX_HOPS=10","handlingStrategy":"validation","validationCode":"fn parse_env_u32(key: &str) -> Result<u32, ConfigError> {\n    let raw = std::env::var(key).unwrap_or_default();\n    raw.trim().parse::<u32>()\n        .map_err(|_| ConfigError::env_parse_error(key, raw.clone()))\n}\n\nlet max_hops = parse_env_u32(ENV_TRUSTED_PROXY_MAX_HOPS)?;","typeGuard":"fn env_parses_as_u32(key: &str) -> bool {\n    std::env::var(key).map(|v| v.trim().parse::<u32>().is_ok()).unwrap_or(true)\n}","tryCatchPattern":"match strict_load() {\n    Err(ConfigError::EnvParseError(key, value)) => {\n        tracing::error!(event = \"config.load\", result = \"env_parse_failed\", key = %key, value = %value, \"set {key} to its documented format\");\n        Err(ConfigError::EnvParseError(key, value))\n    }\n    other => other,\n}","preventionTips":["Document the exact grammar (base-10 integer, true/false) for every typed variable and link it from error messages","Strip whitespace and reject empty strings uniformly in env parsing helpers","Add a config lint command that pre-parses all typed variables and reports every offender in one pass"],"tags":["rust","environment-variables","configuration","parsing","trusted-proxies"],"backgroundTag":"env-var-parse-failed","analyzedSha":"35af688cd9d41b4346fbe27dcf7250ba72046c1f","analyzedAt":"2026-08-20T21:57:04.799Z","contentChangedAt":"2026-08-20T21:57:04.799Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}