{"id":"1c133e1a8b39a79d","repo":"rust-lang/cargo","slug":"failed-to-parse-the-version-requirement-for-d","errorCode":null,"errorMessage":"failed to parse the version requirement `{}` for dependency `{}`","messagePattern":"failed to parse the version requirement `(.+?)` for dependency `(.+?)`","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/workspace/dependency.rs","lineNumber":128,"sourceCode":"            DepKind::Build => Some(\"build\"),\n        }\n        .serialize(s)\n    }\n}\n\nimpl Dependency {\n    /// Attempt to create a `Dependency` from an entry in the manifest.\n    pub fn parse(\n        name: impl Into<InternedString>,\n        version: Option<&str>,\n        source_id: SourceId,\n    ) -> CargoResult<Dependency> {\n        let name = name.into();\n        let (specified_req, version_req) = match version {\n            Some(v) => match VersionReq::parse(v) {\n                Ok(req) => (true, OptVersionReq::Req(req)),\n                Err(err) => {\n                    return Err(anyhow::Error::new(err).context(format!(\n                        \"failed to parse the version requirement `{}` for dependency `{}`\",\n                        v, name,\n                    )));\n                }\n            },\n            None => (false, OptVersionReq::Any),\n        };\n\n        let mut ret = Dependency::new_override(name, source_id);\n        {\n            let ptr = Arc::make_mut(&mut ret.inner);\n            ptr.only_match_name = false;\n            ptr.req = version_req;\n            ptr.specified_req = specified_req;\n        }\n        Ok(ret)\n    }\n","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/dependency.rs#L110-L146","documentation":"Raised in `Dependency::parse` (src/workspace/dependency.rs:128) when `semver::VersionReq::parse(v)` returns an `Err` for the version string of a dependency. The original parse error is wrapped with a context message naming the bad requirement and the dependency, giving `failed to parse the version requirement \\\"<v>\\\" for dependency \\\"<name>\\\"`.","triggerScenarios":"Any dependency whose `version = \"...\"` string is not a valid semver version requirement: typos like `\"^1..2\"`, `\">>1.0\"`, `\"1.0.0-\"`, bare `\"latest\"`, or stray characters. `VersionReq::parse` fails and the context is attached.","commonSituations":"Hand-editing Cargo.toml and introducing a typo; using npm/cargo-style `\"*\"` where unsupported; pasting a version from a release notes page with extra text; migration tooling emitting malformed requirements; caret/tilde confusion across ecosystems.","solutions":["Validate the version string against semver requirement grammar (e.g. `cargo metadata` or the `semver` crate) and correct it.","Use a simple exact or caret form first (`\"1.2.3\"` or `\"^1.2.3\"`) to isolate the issue.","Check the dependency's actual published versions and use a valid comparator against them."],"exampleFix":"# before\n[dependencies]\nserde = { version = \"^1..0\" }\n# after\n[dependencies]\nserde = { version = \"^1.0\" }","handlingStrategy":"validation","validationCode":"use semver::VersionReq;\nfn valid_version_req(v: &str) -> bool { VersionReq::parse(v).is_ok() }\n// before writing a dependency, assert valid_version_req(&version_string)","typeGuard":null,"tryCatchPattern":"match Dependency::parse(name, Some(v), sid) {\n    Err(e) if e.to_string().contains(\"failed to parse the version requirement\") => { /* prompt user */ }\n    res => res,\n}","preventionTips":["Lint Cargo.toml version strings with `cargo metadata` or `toml`+`semver` in CI.","Use caret or exact forms to avoid exotic syntax.","Validate programmatically generated manifests."],"tags":["cargo","dependency","semver","version","manifest"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}