nikivdev/code · error
timeout must be a positive finite number
Error message
timeout must be a positive finite number
What it means
timeout_from_secs validates a caller-supplied f64 timeout in seconds before converting it to a Duration. It rejects NaN, infinities, zero, and negative values because Duration::from_secs_f64 would panic on them. This is pure input validation guarding against a downstream panic.
Source
Thrown at src/url_inspect.rs:894
};
Ok(UrlInspectResult {
reference: url.to_string(),
provider: "direct".to_string(),
final_url: Some(final_url),
status_code: Some(status.as_u16()),
content_type,
title,
description,
excerpt,
markdown,
cache_hit: None,
})
}
fn timeout_from_secs(seconds: f64) -> Result<Duration> {
if !seconds.is_finite() || seconds <= 0.0 {
bail!("timeout must be a positive finite number");
}
Ok(Duration::from_secs_f64(seconds))
}
fn cloudflare_credentials() -> Result<Option<(String, String)>> {
let account_id = load_secret_env_var("CLOUDFLARE_ACCOUNT_ID")?;
let api_token = load_secret_env_var("CLOUDFLARE_API_TOKEN")?;
match (account_id, api_token) {
(Some(account_id), Some(api_token)) => Ok(Some((account_id, api_token))),
(None, None) => Ok(None),
(Some(_), None) => {
bail!("missing CLOUDFLARE_API_TOKEN; set it in shell env or Flow personal env store")
}
(None, Some(_)) => {
bail!("missing CLOUDFLARE_ACCOUNT_ID; set it in shell env or Flow personal env store")
}
}
}View on GitHub (pinned to a747e741ae)
Solutions
- Pass a positive finite value, e.g. timeout_seconds: 30.0.
- Validate/clamp user input before calling: ensure the value parses as a finite positive f64.
- If 'unlimited' was intended, use a large finite sentinel (e.g. 3600.0) since 0/negative is rejected.
- Fix the config source (env var, JSON) so it supplies a real number instead of 0 or null-coerced 0.0.
Example fix
// before
let timeout = config.timeout_seconds; // 0.0 from default
// after
let timeout = if config.timeout_seconds.is_finite() && config.timeout_seconds > 0.0 {
config.timeout_seconds
} else {
30.0 // sane default
}; Defensive patterns
Strategy: validation
Validate before calling
fn valid_timeout(seconds: f64) -> bool {
seconds.is_finite() && seconds > 0.0
}
assert!(valid_timeout(config.timeout_seconds), "timeout must be a positive finite number"); Prevention
- Clamp/validate timeout inputs at the config-parsing boundary.
- Use a default (e.g. 30s) when the value is missing or zero.
- Avoid sentinel 0/negative for 'no timeout'; use a large finite value.
- Parse timeouts as f64 explicitly and reject NaN early.
When it happens
Trigger: Calling inspect_compact, inspect, or crawl with a timeout_seconds value that is 0.0, negative, NaN, or infinite — typically parsed from CLI flags or JSON config.
Common situations: Config file containing timeout: 0, a misparsed or missing numeric field defaulting to 0.0, NaN produced by a failed float parse, or a negative value meant to mean 'no timeout'.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- Docs template root not found: {}
- Unable to resolve docs for {}
- No env keys configured. Add cloudflare.env_keys or cloudflar
- Usage: f hash <paths or unhash args>
- missing CLOUDFLARE_API_TOKEN; set it in shell env or Flow pe
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/2693cfe655b4ceb5.
Report an issue: GitHub.