Hmbown/CodeWhale · error
.context_window must be greater than 0
Error message
{name}.context_window must be greater than 0 What it means
Provider config validation rejects a context_window explicitly set to 0. Context windows must be positive (or left unset to use the default); zero is meaningless and would break token budgeting. Thrown by validate_provider_context_window at config.rs:4078.
Solutions
- Set context_window to a positive integer matching the provider's real limit (e.g. 200000).
- Remove the key entirely to use the library default.
- Fix the upstream source (env var or script) that produced 0.
Example fix
// before [providers.myprovider] context_window = 0 // after [providers.myprovider] context_window = 200000
Defensive patterns
Strategy: validation
Validate before calling
if let Some(w) = provider.context_window {
if w == 0 { return Err("context_window must be > 0"); }
} Prevention
- Omit context_window rather than writing 0 as a placeholder.
- Guard generators against defaulting lookups to 0.
When it happens
Trigger: A provider entry in config has `context_window = 0` (only Some(0) triggers; None and positive values pass).
Common situations: Computing the window from an env/CLI value that defaulted to 0; copy-paste of a template with a placeholder 0; a script generating config where a lookup failed and yielded 0.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- custom provider ' ' must set [providers. ].kind =…
- Invalid default_text_model
- Invalid provider ' ': expected .
- .model_context_windows. must be greater than 0
- unknown field ' ' for built-in provider ' ': expected one…
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/1b0fa5b9c075925e.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/config.rs:4078
("providers.meta", &self.meta),
("providers.xai", &self.xai),
];
for (name, config) in builtins {
validate_provider_context_window(name, config.context_window)?;
validate_model_context_windows(name, config.model_context_windows.as_ref())?;
}
for (name, config) in &self.custom {
let name = format!("providers.{name}");
validate_provider_context_window(&name, config.context_window)?;
validate_model_context_windows(&name, config.model_context_windows.as_ref())?;
}
Ok(())
}
}
fn validate_provider_context_window(name: &str, value: Option<u32>) -> Result<()> {
if value == Some(0) {
anyhow::bail!("{name}.context_window must be greater than 0");
}
Ok(())
}
fn validate_model_context_windows(
name: &str,
table: Option<&std::collections::BTreeMap<String, u32>>,
) -> Result<()> {
if let Some(table) = table {
for (model, window) in table {
if *window == 0 {
anyhow::bail!("{name}.model_context_windows.{model} must be greater than 0");
}
}
}
Ok(())
}
View on GitHub (pinned to 73e0f67d83)