Hmbown/CodeWhale · error
context_window must be greater than 0
Error message
context_window must be greater than 0
What it means
Thrown by `parse_context_window` when the parsed `context_window` value is 0. The context window is a token budget and must be a positive count; a zero value would make the budget meaningless. Parsing itself must already have succeeded as a u32.
Solutions
- Set `context_window` to the provider model's actual token limit (e.g. "128000").
- Remove the `context_window` override entirely to fall back to the model's default.
- Never use 0 to mean 'unlimited' — the field requires a positive integer.
Example fix
// before context_window = "0" // after context_window = "200000"
Defensive patterns
Strategy: validation
Validate before calling
fn valid_context_window(v: &str) -> bool {
v.trim().parse::<u32>().map(|n| n > 0).unwrap_or(false)
} Try / catch
match parse_context_window(value) {
Err(e) if e.to_string().contains("greater than 0") => {
// fall back to the model default instead of forcing 0
config.providers.for_provider_mut(provider).context_window = None;
Ok(())
}
other => other,
} Prevention
- Never write 0 for context_window; omit the field to use the model default.
- Validate positive integer inputs in any CLI/config UI before persisting.
- Document that context_window is a token count, not a boolean/unlimited flag.
When it happens
Trigger: Setting a provider's `context_window` field (via `set_provider_config_value` or the ConfigToml setter) to "0" — the string parses fine as u32 but fails the >0 check.
Common situations: User typed `context_window = "0"` intending 'unlimited' or left a placeholder value; a template or script emitted 0 as a default.
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
- Failed to update setting
- Failed to update setting: invalid
- agent profile provider cannot be empty
- agent profile provider must be a simple provider id
- api_key cannot be empty string
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/b9aae4b2312c3330.
Report an issue: GitHub.
Appendix: source
Thrown at crates/config/src/lib.rs:1160
fn get_provider_config_display_value(
config: &ProviderConfigToml,
field: ProviderConfigField,
) -> Option<String> {
match field {
ProviderConfigField::ApiKey => config.api_key.as_deref().map(redact_secret),
ProviderConfigField::HttpHeaders => {
serialize_http_headers_for_display(&config.http_headers)
}
_ => get_provider_config_value(config, field),
}
}
fn parse_context_window(value: &str) -> Result<u32> {
let parsed = value.trim().parse::<u32>().with_context(|| {
format!("invalid context_window '{value}': expected a positive token count")
})?;
if parsed == 0 {
bail!("context_window must be greater than 0");
}
Ok(parsed)
}
fn set_provider_config_value(
config: &mut ConfigToml,
provider: ProviderKind,
field: ProviderConfigField,
value: &str,
) -> Result<()> {
if provider == ProviderKind::Antigravity {
bail!(LEGACY_ANTIGRAVITY_TOMBSTONE_MESSAGE);
}
match field {
ProviderConfigField::Vendor => {
if provider != ProviderKind::Openrouter {
bail!("vendor is only supported by providers.openrouter");
}View on GitHub (pinned to 73e0f67d83)