sigoden/aichat · error
Invalid value
Error message
Invalid value '{}' What it means
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.
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.
Example fix
// before export AICHAT_TEMPERATURE=high // after export AICHAT_TEMPERATURE=0.7
Defensive patterns
Strategy: validation
Validate before calling
fn is_parsable_int(s: &str) -> bool { s.parse::<i64>().is_ok() } // apply per target type before export Type guard
fn as_f64_env(key: &str) -> Option<f64> { std::env::var(key).ok().and_then(|v| v.trim().parse().ok()) } Try / catch
match parse_value::<f64>(&raw) { Ok(v) => v, Err(e) => { eprintln!("{e}; expected a number"); return Ok(()); } } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.
AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09).
Data as JSON: /api/errors/18632b082ae04bc8.
Report an issue: GitHub.
Appendix: source
Thrown at src/config/mod.rs:2695
fn read_env_value<T>(key: &str) -> Option<Option<T>>
where
T: std::str::FromStr,
{
let value = env::var(key).ok()?;
let value = parse_value(&value).ok()?;
Some(value)
}
fn parse_value<T>(value: &str) -> Result<Option<T>>
where
T: std::str::FromStr,
{
let value = if value == "null" {
None
} else {
let value = match value.parse() {
Ok(value) => value,
Err(_) => bail!("Invalid value '{}'", value),
};
Some(value)
};
Ok(value)
}
fn read_env_bool(key: &str) -> Option<Option<bool>> {
let value = env::var(key).ok()?;
Some(parse_bool(&value))
}
fn complete_bool(value: bool) -> Vec<String> {
vec![(!value).to_string()]
}
fn complete_option_bool(value: Option<bool>) -> Vec<String> {
match value {
Some(true) => vec!["false".to_string(), "null".to_string()],View on GitHub (pinned to 82976d349a)