{"record":{"id":"1d6b984279d6ae2e","repo":"ducaale/xh","slug":"connection-timeout-is-too-big","errorCode":null,"errorMessage":"Connection timeout is too big","messagePattern":"Connection timeout is too big","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli.rs","lineNumber":1206,"sourceCode":"#[derive(Debug, Clone)]\npub struct Timeout(Duration);\n\nimpl Timeout {\n    pub fn as_duration(&self) -> Option<Duration> {\n        Some(self.0).filter(|t| !t.is_zero())\n    }\n}\n\nimpl FromStr for Timeout {\n    type Err = anyhow::Error;\n\n    fn from_str(sec: &str) -> anyhow::Result<Timeout> {\n        match f64::from_str(sec) {\n            Ok(s) if !s.is_nan() => {\n                if s.is_sign_negative() {\n                    Err(anyhow!(\"Connection timeout is negative\"))\n                } else if s >= Duration::MAX.as_secs_f64() || s.is_infinite() {\n                    Err(anyhow!(\"Connection timeout is too big\"))\n                } else {\n                    Ok(Timeout(Duration::from_secs_f64(s)))\n                }\n            }\n            _ => Err(anyhow!(\"Connection timeout is not a valid number\")),\n        }\n    }\n}\n\n#[derive(Debug, Clone, PartialEq, Eq)]\npub enum Proxy {\n    Http(Url),\n    Https(Url),\n    All(Url),\n}\n\nimpl FromStr for Proxy {\n    type Err = anyhow::Error;","sourceCodeStart":1188,"sourceCodeEnd":1224,"githubUrl":"https://github.com/ducaale/xh/blob/2404aceecc08b0b2d100fedc96f57745cd5904dc/src/cli.rs#L1188-L1224","documentation":"Validation guard in Timeout's FromStr impl: the --connection-timeout value is finite and non-negative but numerically too large to be represented as a Duration — it equals or exceeds Duration::MAX.as_secs_f64(), or is infinite. Duration::from_secs_f64 would panic on such input, so it is rejected up front. Fires when the user passes an absurdly large timeout like 1e30.","triggerScenarios":"Passing --timeout=inf, --timeout=1e400 (parses to inf), or a finite value >= ~1.8e19 seconds (Duration::MAX).","commonSituations":"Using 'inf' to mean 'wait forever'; passing enormous sentinel values from scripts.","solutions":["Use a large but finite value below Duration::MAX (e.g. --timeout=1e9)","Remove the timeout to rely on defaults for effectively-unbounded waiting","Validate computed timeout values against Duration::MAX before passing"],"exampleFix":"# before\nhttp --timeout=inf GET example.org\n# after\nhttp --timeout=3600 GET example.org","handlingStrategy":"validation","validationCode":"// validate the magnitude before invoking\nlet v: f64 = timeout_str.parse()?;\nif v.is_infinite() || v >= std::time::Duration::MAX.as_secs_f64() {\n    return Err(\"timeout too large; use a finite value\");\n}","typeGuard":"fn timeout_fits_duration(s: &str) -> bool {\n    s.parse::<f64>().map(|v| v.is_finite() && v < std::time::Duration::MAX.as_secs_f64()).unwrap_or(false)\n}","tryCatchPattern":"let out = Command::new(\"http\").args([\"--timeout\", &timeout_str, \"GET\", url]).output()?;\nif !out.status.success() && String::from_utf8_lossy(&out.stderr).contains(\"timeout is too big\") {\n    eprintln!(\"use a finite timeout, e.g. --timeout=3600\");\n}","preventionTips":["Never pass 'inf' or 1e400-style sentinels; omit --timeout for unbounded waits","Cap timeouts to a sane maximum in wrapper scripts","Validate against Duration::MAX when computing timeouts programmatically"],"tags":["cli","timeout","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"2404aceecc08b0b2d100fedc96f57745cd5904dc","analyzedAt":"2026-09-13T19:13:33.814Z","contentChangedAt":"2026-09-13T19:13:33.814Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}