{"record":{"id":"8af355c130b0cee1","repo":"FuelLabs/sway","slug":"missing-dependency-name","errorCode":null,"errorMessage":"missing dependency name","messagePattern":"missing dependency name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"forc-pkg/src/manifest/dep_modifier.rs","lineNumber":253,"sourceCode":"#[derive(Clone, Debug, Default)]\npub struct DepSpec {\n    pub name: String,\n    pub version_req: Option<String>,\n}\n\nimpl FromStr for DepSpec {\n    type Err = anyhow::Error;\n\n    fn from_str(s: &str) -> anyhow::Result<Self> {\n        if s.trim().is_empty() {\n            bail!(\"Dependency spec cannot be empty\");\n        }\n\n        let mut s = s.trim().split('@');\n\n        let name = s\n            .next()\n            .ok_or_else(|| anyhow::anyhow!(\"missing dependency name\"))?;\n\n        let version_req = s.next().map(|s| s.to_string());\n\n        if let Some(ref v) = version_req {\n            semver::VersionReq::parse(v)\n                .map_err(|_| anyhow::anyhow!(\"invalid version requirement `{v}`\"))?;\n        }\n\n        Ok(Self {\n            name: name.to_string(),\n            version_req,\n        })\n    }\n}\n\nimpl fmt::Display for DepSpec {\n    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n        match &self.version_req {","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc-pkg/src/manifest/dep_modifier.rs#L235-L271","documentation":"DepSpec::from_str parses 'name@version-req' arguments accepted by forc add. This error is the guard for a spec with no name segment before '@'. In the shipped code it is unreachable in practice: empty/whitespace-only specs are rejected one line earlier ('Dependency spec cannot be empty'), and str::split('@') always yields a first element - a spec like '@1.0.0' produces an empty-string name that slips past this check. Treat any sighting as a malformed argument string.","triggerScenarios":"Intended for arguments like '@1.0.0' (version with no package name) passed to forc add; reachable only through unusual inputs given the earlier empty-spec bail.","commonSituations":"Shell expansion or quoting accidents eating the name; copy-paste of only the version half of a spec; scripted forc add invocations building the argument string wrongly.","solutions":["Pass the package name explicitly: forc add mydep or forc add mydep@^1.0.0.","Inspect the exact argv your script/shell produces (echo the command) to find where the name was dropped.","Quote the whole spec so @ is not interpreted by the shell."],"exampleFix":"# before\n$ forc add @1.2.3\n\n# after\n$ forc add mydep@1.2.3","handlingStrategy":"validation","validationCode":"// Rust, validate a forc add spec before passing it on:\nfn valid_dep_spec(s: &str) -> bool {\n    let s = s.trim();\n    !s.is_empty() && s.split('@').next().map(|n| !n.is_empty()).unwrap_or(false)\n}","typeGuard":"// Structural guard for 'name[@version]':\nfn is_wellformed_dep_spec(s: &str) -> bool {\n    let mut parts = s.trim().splitn(2, '@');\n    let name = parts.next().unwrap_or(\"\");\n    !name.is_empty() && name.chars().all(|c| c.is_alphanumeric() || c=='-' || c=='_')\n}","tryCatchPattern":"// DepSpec::from_str is Result-returning; map to a CLI-usage message:\nmatch DepSpec::from_str(arg) {\n    Ok(spec) => { /* proceed */ }\n    Err(_) => eprintln!(\"usage: forc add <name>[@<version-req>]\"),\n}","preventionTips":["Always pass the package name: forc add name or name@version.","Quote specs to stop the shell from mangling @ or dropping tokens.","Echo assembled commands in scripts before executing them."],"tags":["forc","cli","dependency","argument-parsing"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}