cross-rs/cross · error

argument should contain `=`

Error message

argument should contain `=`

What it means

parse_equal_arg parses CLI arguments of the form `name=value`. It uses split_once('=') and unwraps the result with .expect("argument should contain `=`"), so the message is raised as a panic (not an eyre error) whenever the argument lacks an '=' separator. The function contract is that callers only invoke it with arguments already known to be `key=value` shaped.

Solutions

  1. Use the `=` form for these flags: `--flag=value` with no space between the flag name and the value.
  2. Check shell quoting/variable expansion so the argument reaches the parser as a single `name=value` token (e.g. quote "--target=$TARGET").
  3. As a library fix, replace the expect with proper error handling returning a Result (map_err to a descriptive invalid-CLI-argument error) instead of panicking.

Example fix

// before
$ xtask run --target x86_64-unknown-linux-gnu
thread 'main' panicked: argument should contain `=`

// after
$ xtask run --target=x86_64-unknown-linux-gnu
Defensive patterns

Strategy: validation

Validate before calling

fn validate_equal_arg(arg: &str) -> Result<(), String> {
    if arg.split_once('=').is_none() {
        return Err(format!("argument `{arg}` must be in name=value form"));
    }
    Ok(())
}

Type guard

fn is_key_value(arg: &str) -> Option<(&str, &str)> { arg.split_once('=') }

Try / catch

catch_unwind(|| cli::parse(args)).unwrap_or_else(|_| {
    eprintln!("invalid argument: expected --flag=value form (with '=')");
    std::process::exit(2);
})

Prevention

When it happens

Trigger: Calling the xtask CLI with a flag that is routed through parse_equal_arg but supplied without '=', e.g. `--platform linux` instead of `--platform=linux`, or a bare flag with no value (`--platform`) reaching the parser.

Common situations: Users type a space-separated flag value out of habit (`--target x86_64-unknown-linux-gnu`) while the parser only accepts `--target=x86_64-unknown-linux-gnu`; scripts concatenate flags incorrectly, dropping the '='; an empty value still works but a completely malformed token (typo, stray space from shell quoting) panics.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of cross-rs/cross@8c1a8aa4b6 (2026-09-13). Data as JSON: /api/errors/bdca004cfd2502bf. Report an issue: GitHub.

Appendix: source

Thrown at src/cli.rs:128

) -> Result<Option<T>> {
    out.push(arg);
    match iter.next() {
        Some(next) => {
            let result = parse(&next)?;
            out.push(store_cb(next)?);
            Ok(Some(result))
        }
        None => Ok(None),
    }
}

fn parse_equal_arg<T>(
    arg: String,
    out: &mut Vec<String>,
    parse: impl Fn(&str) -> Result<T>,
    store_cb: impl Fn(String) -> Result<String>,
) -> Result<T> {
    let (first, second) = arg.split_once('=').expect("argument should contain `=`");
    let result = parse(second)?;
    out.push(format!("{first}={}", store_cb(second.to_owned())?));

    Ok(result)
}

fn parse_manifest_path(path: &str) -> Result<Option<PathBuf>> {
    let p = PathBuf::from(path);
    Ok(absolute_path(p).ok())
}

fn parse_target_dir(path: &str) -> Result<PathBuf> {
    absolute_path(PathBuf::from(path))
}

fn identity(arg: String) -> Result<String> {
    Ok(arg)
}

View on GitHub (pinned to 8c1a8aa4b6)