FuelLabs/sway · error

missing dependency name

Error message

missing dependency name

What it means

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.

Source

Thrown at forc-pkg/src/manifest/dep_modifier.rs:253

#[derive(Clone, Debug, Default)]
pub struct DepSpec {
    pub name: String,
    pub version_req: Option<String>,
}

impl FromStr for DepSpec {
    type Err = anyhow::Error;

    fn from_str(s: &str) -> anyhow::Result<Self> {
        if s.trim().is_empty() {
            bail!("Dependency spec cannot be empty");
        }

        let mut s = s.trim().split('@');

        let name = s
            .next()
            .ok_or_else(|| anyhow::anyhow!("missing dependency name"))?;

        let version_req = s.next().map(|s| s.to_string());

        if let Some(ref v) = version_req {
            semver::VersionReq::parse(v)
                .map_err(|_| anyhow::anyhow!("invalid version requirement `{v}`"))?;
        }

        Ok(Self {
            name: name.to_string(),
            version_req,
        })
    }
}

impl fmt::Display for DepSpec {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match &self.version_req {

View on GitHub (pinned to 47e5e902fa)

Solutions

  1. Pass the package name explicitly: forc add mydep or forc add mydep@^1.0.0.
  2. Inspect the exact argv your script/shell produces (echo the command) to find where the name was dropped.
  3. Quote the whole spec so @ is not interpreted by the shell.

Example fix

# before
$ forc add @1.2.3

# after
$ forc add mydep@1.2.3
Defensive patterns

Strategy: validation

Validate before calling

// Rust, validate a forc add spec before passing it on:
fn valid_dep_spec(s: &str) -> bool {
    let s = s.trim();
    !s.is_empty() && s.split('@').next().map(|n| !n.is_empty()).unwrap_or(false)
}

Type guard

// Structural guard for 'name[@version]':
fn is_wellformed_dep_spec(s: &str) -> bool {
    let mut parts = s.trim().splitn(2, '@');
    let name = parts.next().unwrap_or("");
    !name.is_empty() && name.chars().all(|c| c.is_alphanumeric() || c=='-' || c=='_')
}

Try / catch

// DepSpec::from_str is Result-returning; map to a CLI-usage message:
match DepSpec::from_str(arg) {
    Ok(spec) => { /* proceed */ }
    Err(_) => eprintln!("usage: forc add <name>[@<version-req>]"),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of FuelLabs/sway@47e5e902fa (2026-08-16). Data as JSON: /api/errors/8af355c130b0cee1. Report an issue: GitHub.