{"record":{"id":"18632b082ae04bc8","repo":"sigoden/aichat","slug":"invalid-value","errorCode":null,"errorMessage":"Invalid value '{}'","messagePattern":"Invalid value '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/config/mod.rs","lineNumber":2695,"sourceCode":"fn read_env_value<T>(key: &str) -> Option<Option<T>>\nwhere\n    T: std::str::FromStr,\n{\n    let value = env::var(key).ok()?;\n    let value = parse_value(&value).ok()?;\n    Some(value)\n}\n\nfn parse_value<T>(value: &str) -> Result<Option<T>>\nwhere\n    T: std::str::FromStr,\n{\n    let value = if value == \"null\" {\n        None\n    } else {\n        let value = match value.parse() {\n            Ok(value) => value,\n            Err(_) => bail!(\"Invalid value '{}'\", value),\n        };\n        Some(value)\n    };\n    Ok(value)\n}\n\nfn read_env_bool(key: &str) -> Option<Option<bool>> {\n    let value = env::var(key).ok()?;\n    Some(parse_bool(&value))\n}\n\nfn complete_bool(value: bool) -> Vec<String> {\n    vec![(!value).to_string()]\n}\n\nfn complete_option_bool(value: Option<bool>) -> Vec<String> {\n    match value {\n        Some(true) => vec![\"false\".to_string(), \"null\".to_string()],","sourceCodeStart":2677,"sourceCodeEnd":2713,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/config/mod.rs#L2677-L2713","documentation":"Thrown by the generic parse_value::<T>() helper (src/config/mod.rs:2695) when a string value fails T::from_str. It is used to parse environment-variable overrides and similar string inputs into typed config values; the literal string \"null\" maps to None, everything else must parse. The message echoes the offending raw string.","triggerScenarios":"Setting an env override (e.g. AICHAT_* variables or mapped config env keys) whose value cannot be parsed into the target type — e.g. a non-numeric string where a number, a non-boolean where a bool (`true`/`false`), or a malformed value for an enum/URL type.","commonSituations":"Exporting AICHAT_TEMPERATURE=high instead of 0.7; AICHAT_MAX_TOKENS with units (\"4k\") instead of a plain integer; whitespace or quotes accidentally included in the env value.","solutions":["Correct the env var / input value to a format the target type parses (numbers unquoted, bools as true/false).","Use the literal string \"null\" to unset an override instead of an empty or invalid value.","Check the type of the config field being overridden and match it exactly."],"exampleFix":"// before\nexport AICHAT_TEMPERATURE=high\n// after\nexport AICHAT_TEMPERATURE=0.7","handlingStrategy":"validation","validationCode":"fn is_parsable_int(s: &str) -> bool { s.parse::<i64>().is_ok() } // apply per target type before export","typeGuard":"fn as_f64_env(key: &str) -> Option<f64> { std::env::var(key).ok().and_then(|v| v.trim().parse().ok()) }","tryCatchPattern":"match parse_value::<f64>(&raw) { Ok(v) => v, Err(e) => { eprintln!(\"{e}; expected a number\"); return Ok(()); } }","preventionTips":["Set env overrides to plain typed literals (0.7, 4096, true)","Use \"null\" explicitly to unset overrides","Trim whitespace and avoid quoting values inside env vars"],"tags":["env-var","parse-error","type-coercion"],"backgroundTag":"invalid-env-var-value","analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}