{"record":{"id":"8233568c6faa3869","repo":"cross-rs/cross","slug":"invalid-toolchain-s","errorCode":null,"errorMessage":"invalid toolchain `{s}`","messagePattern":"invalid toolchain `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/rustc.rs","lineNumber":324,"sourceCode":"}\n\nimpl std::str::FromStr for Toolchain {\n    type Err = eyre::Report;\n\n    fn from_str(s: &str) -> Result<Self, Self::Err> {\n        fn dig(s: &str) -> bool {\n            s.chars().all(|c: char| c.is_ascii_digit())\n        }\n        if let Some((channel, parts)) = s.split_once('-') {\n            if parts.starts_with(|c: char| c.is_ascii_digit()) {\n                // a date, YYYY-MM-DD\n                let mut split = parts.splitn(4, '-');\n                let ymd = [split.next(), split.next(), split.next()];\n                let ymd = match ymd {\n                    [Some(y), Some(m), Some(d)] if dig(y) && dig(m) && dig(d) => {\n                        format!(\"{y}-{m}-{d}\")\n                    }\n                    _ => eyre::bail!(\"invalid toolchain `{s}`\"),\n                };\n                Ok(Toolchain {\n                    channel: channel.to_owned(),\n                    date: Some(ymd),\n                    host: split.next().map(|s| s.into()),\n                    is_custom: false,\n                    full: s.to_owned(),\n                })\n            } else {\n                // channel-host\n                Ok(Toolchain {\n                    channel: channel.to_owned(),\n                    date: None,\n                    host: Some(parts.into()),\n                    is_custom: false,\n                    full: s.to_owned(),\n                })\n            }","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/cross-rs/cross/blob/8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27/src/rustc.rs#L306-L342","documentation":"`Toolchain::from_str` parses rustup-style toolchain names like `stable-2023-01-10-x86_64-unknown-linux-gnu`. When the optional date component is present but not three 2-digit-separated groups of digits (Y-M-D), parsing bails with `invalid toolchain \\`{s}\\``. It guards against malformed toolchain identifiers before constructing the struct.","triggerScenarios":"Passing a toolchain string whose date part is malformed, e.g. `stable-20230101-x86_64-unknown-linux-gnu`, `nightly-2023-1-10-...`, or extra/missing dashes so `splitn(4,'-')` does not yield three digit-only parts.","commonSituations":"Hand-edited rust-toolchain files; copy-pasted toolchain names with wrong dash grouping; scripts that format dates as YYYYMMDD instead of YYYY-MM-DD; toolchain names containing extra hyphens from target triples interacting with splitn.","solutions":["Use the canonical rustup format: `channel[-YYYY-MM-DD][-host-triple]`, e.g. `nightly-2023-05-01-x86_64-unknown-linux-gnu`.","Remove the date entirely (`nightly`) or use the full official name from `rustup toolchain list`.","Check your rust-toolchain.toml / RUSTUP_TOOLCHAIN value for stray characters or double dashes.","Validate the string with a regex like `^(stable|beta|nightly|\\d+\\.\\d+(\\.\\d+)?)(-\\d{4}-\\d{2}-\\d{2})?(-[a-z0-9_-]+)?$` before passing it in."],"exampleFix":"// before\nRUSTUP_TOOLCHAIN=nightly-20230501-x86_64-unknown-linux-gnu\n// after\nRUSTUP_TOOLCHAIN=nightly-2023-05-01-x86_64-unknown-linux-gnu","handlingStrategy":"validation","validationCode":"const TOOLCHAIN_RE: &str = r\"^[A-Za-z0-9._+]+(-\\d{4}-\\d{2}-\\d{2})?(-[a-z0-9_-]+)?$\";\nfn valid_toolchain(s: &str) -> bool { regex::Regex::new(TOOLCHAIN_RE).unwrap().is_match(s) }","typeGuard":null,"tryCatchPattern":"let toolchain = Toolchain::from_str(input)\n    .map_err(|e| format!(\"Bad toolchain '{input}': use channel[-YYYY-MM-DD][-triple], e.g. nightly-2023-05-01\"))?;","preventionTips":["Always use rustup's canonical naming: channel, optional -YYYY-MM-DD date, optional host triple.","Never hand-format dates as YYYYMMDD; zero-pad month and day.","Take toolchain names verbatim from `rustup toolchain list` rather than constructing them."],"tags":["rustup","toolchain","parsing","format"],"backgroundTag":"invalid-argument-format","analyzedSha":"8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27","analyzedAt":"2026-09-13T15:10:43.988Z","contentChangedAt":"2026-09-13T15:10:43.988Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}