cross-rs/cross · error · eyre::ErrReport

invalid platform specified

Error message

invalid platform specified

What it means

`ImagePlatform::from_str` parses a platform triple (os/arch[/variant]) and fails when the string does not split into the expected components, i.e. it lacks the required os/arch segments separated appropriately.

Solutions

  1. Use the full os/arch form: e.g. `linux/amd64`, `linux/arm64`, `windows/amd64`.
  2. Check whether you meant a Rust target triple and convert it (e.g. via from_target/new) instead of from_str.
  3. Count the separators — the value needs both os and arch components.

Example fix

// before
ImagePlatform::from_str("amd64")? // fails: missing os
// after
ImagePlatform::from_str("linux/amd64")?
Defensive patterns

Strategy: validation

Validate before calling

fn is_platform_str(s: &str) -> bool {
    let parts: Vec<&str> = s.split('/').collect();
    parts.len() >= 2 && parts.iter().all(|p| !p.is_empty())
}

Type guard

fn parse_platform(s: &str) -> Option<(String, String)> {
    let mut it = s.split('/');
    Some((it.next()?.to_string(), it.next()?.to_string()))
}

Prevention

When it happens

Trigger: Passing a malformed platform string such as "linux", "x86_64" (missing os), an empty string, or a string with too few `/`-separated parts to `ImagePlatform::from_str` or the platform CLI flag.

Common situations: Hand-typing a `--platform` flag value, copying a target triple like `x86_64-unknown-linux-gnu` where a platform string `linux/amd64` is expected, or CI variables set incorrectly.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at src/docker/image.rs:256

            "linux/amd64" => return Ok(Self::X86_64_UNKNOWN_LINUX_GNU),
            "linux/arm64" | "linux/arm64/v8" => return Ok(Self::AARCH64_UNKNOWN_LINUX_GNU),
            _ => {}
        };

        if let Some((platform, toolchain)) = s.split_once('=') {
            let image_toolchain = toolchain.into();
            let (os, arch, variant) = if let Some((os, rest)) = platform.split_once('/') {
                let os: StrDeserializer<'_, SerdeError> = os.into_deserializer();
                let (arch, variant) = if let Some((arch, variant)) = rest.split_once('/') {
                    let arch: StrDeserializer<'_, SerdeError> = arch.into_deserializer();
                    (arch, Some(variant))
                } else {
                    let arch: StrDeserializer<'_, SerdeError> = rest.into_deserializer();
                    (arch, None)
                };
                (os, arch, variant)
            } else {
                eyre::bail!("invalid platform specified")
            };
            Ok(ImagePlatform {
                architecture: Architecture::deserialize(arch)?,
                os: Os::deserialize(os)?,
                variant: variant.map(ToOwned::to_owned),
                target: image_toolchain,
            })
        } else {
            Ok(ImagePlatform::from_target(s.into())
                .wrap_err_with(|| format!("could not map `{s}` to a platform"))?)
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Architecture {
    I386,

View on GitHub (pinned to 8c1a8aa4b6)