wasmerio/wasmer · error

Invalid --map-command flag - alias cannot be empty: '{item}'

Error message

Invalid --map-command flag - alias cannot be empty: '{item}'

What it means

build_mapped_commands parses each --map-command item as ALIAS=HOST_PATH, trimming both sides. If the alias side (before '=') is empty, the mapping is meaningless so it is rejected with this message, which echoes the raw offending item. The TODO notes the host path is not yet canonicalized or checked for existence.

Source

Thrown at lib/cli/src/commands/run/wasi.rs:555

        Ok((have_current_dir, mapped_dirs))
    }

    pub fn build_mapped_commands(&self) -> Result<Vec<MappedCommand>, anyhow::Error> {
        self.map_commands
            .iter()
            .map(|item| {
                let (a, b) = item.split_once('=').with_context(|| {
                    format!(
                        "Invalid --map-command flag: expected <ALIAS>=<HOST_PATH>, got '{item}'"
                    )
                })?;

                let a = a.trim();
                let b = b.trim();

                if a.is_empty() {
                    bail!("Invalid --map-command flag - alias cannot be empty: '{item}'");
                }
                // TODO(theduke): check if host command exists, and canonicalize PathBuf.
                if b.is_empty() {
                    bail!("Invalid --map-command flag - host path cannot be empty: '{item}'");
                }

                Ok(MappedCommand {
                    alias: a.to_string(),
                    target: b.to_string(),
                })
            })
            .collect::<Result<Vec<_>, anyhow::Error>>()
    }

    pub fn capabilities(&self) -> Capabilities {
        let mut caps = Capabilities::default();

        if self.http_client {

View on GitHub (pinned to 8c4b9ee9d3)

Solutions

  1. Provide a non-empty alias before the '=' sign, e.g. --map-command ls=/bin/ls
  2. Inspect the offending item echoed in the message and fix the flag ordering/separator
  3. Filter out empty entries when building --map-command flags in scripts

Example fix

// before
wasmer run app.wasm --map-command =/bin/ls
// after
wasmer run app.wasm --map-command ls=/bin/ls
Defensive patterns

Strategy: validation

Validate before calling

fn validate_map_command(item: &str) -> Result<(), String> {
    let (a, b) = item.split_once('=')
        .ok_or_else(|| format!("--map-command must be ALIAS=HOST_PATH, got {item:?}"))?;
    if a.trim().is_empty() { Err(format!("empty alias in {item:?}")) } else { Ok(()) }
}

Type guard

fn has_nonempty_alias(item: &str) -> bool {
    item.split_once('=').map(|(a, _)| !a.trim().is_empty()).unwrap_or(false)
}

Try / catch

match wasmer_run_with_map_commands(&items) {
    Err(e) if e.to_string().contains("alias cannot be empty") => {
        let fixed: Vec<_> = items.iter().filter(|i| has_nonempty_alias(i)).collect();
        wasmer_run_with_map_commands(&fixed)
    }
    other => other,
}

Prevention

When it happens

Trigger: Passing a --map-command item like `=/bin/ls`, ` =/bin/ls`, or a malformed `=path` where the text before '=' trims to empty during prepare().

Common situations: Leading '=' typo in the flag; programmatically built flag strings where the alias variable was empty; splitting a comma/whitespace-separated list that produced an empty alias segment.

Related errors


AI-assisted analysis of wasmerio/wasmer@8c4b9ee9d3 (2026-09-01). Data as JSON: /api/errors/a1e02eb75f6fa357. Report an issue: GitHub.