neondatabase/neon · warning

Invalid format '{s}', a valid example is 'attached:1'

Error message

Invalid format '{s}', a valid example is 'attached:1'

What it means

storcon_cli parses placement policy arguments via FromStr: only 'detached', 'secondary', or 'attached:<n>' with n an unsigned integer are accepted. This error fires when the value starts with 'attached:' but the remainder does not parse as usize.

Source

Thrown at control_plane/storcon_cli/src/main.rs:357

    command: Command,
}

#[derive(Debug, Clone)]
struct PlacementPolicyArg(PlacementPolicy);

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

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "detached" => Ok(Self(PlacementPolicy::Detached)),
            "secondary" => Ok(Self(PlacementPolicy::Secondary)),
            _ if s.starts_with("attached:") => {
                let mut splitter = s.split(':');
                let _prefix = splitter.next().unwrap();
                match splitter.next().and_then(|s| s.parse::<usize>().ok()) {
                    Some(n) => Ok(Self(PlacementPolicy::Attached(n))),
                    None => Err(anyhow::anyhow!(
                        "Invalid format '{s}', a valid example is 'attached:1'"
                    )),
                }
            }
            _ => Err(anyhow::anyhow!(
                "Unknown placement policy '{s}', try detached,secondary,attached:<n>"
            )),
        }
    }
}

#[derive(Debug, Clone)]
struct SkSchedulingPolicyArg(SkSchedulingPolicy);

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

    fn from_str(s: &str) -> Result<Self, Self::Err> {

View on GitHub (pinned to 8f60b04da4)

Solutions

  1. Use a non-negative integer after the colon, e.g. attached:1
  2. Quote/escape the argument so the shell does not mangle it
  3. Validate the value in the calling script before invoking the CLI

Example fix

# before
--placement-policy attached:one
# after
--placement-policy attached:1
Defensive patterns

Strategy: type-guard

Validate before calling

fn parse_placement(s: &str) -> Result<PlacementPolicyArg, String> {
    s.parse().map_err(|e| format!("{e}; expected detached|secondary|attached:<usize>"))
}

Type guard

fn is_valid_placement_policy(s: &str) -> bool {
    if matches!(s, "detached" | "secondary") { return true; }
    let mut parts = s.split(':');
    parts.next() == Some("attached")
        && parts.next().map(|n| n.parse::<usize>().is_ok()).unwrap_or(false)
        && parts.next().is_none()
}

Prevention

When it happens

Trigger: Passing attached: (empty suffix), attached:one, attached:-1, attached:1.5, or attached:0x2 — the prefix matches but the suffix fails usize::from_str.

Common situations: Scripts building the flag from variables that may be empty or non-numeric, copy-pasting documentation placeholders into commands.

Related errors


AI-assisted analysis of neondatabase/neon@8f60b04da4 (2026-08-16). Data as JSON: /api/errors/921456abeae12f54. Report an issue: GitHub.