astrid-runtime/astrid · error

keypair name must be at most

Error message

keypair name must be at most {MAX_NAME_LEN} chars (got {})

What it means

validate_name enforces the keypair naming rules before any keypair operation. A keypair name longer than MAX_NAME_LEN bytes is rejected with this error, keeping names compatible with principal-id length limits and filesystem/socket path constraints.

Solutions

  1. Shorten the keypair name to at most MAX_NAME_LEN chars
  2. Use `aos keypair generate` without --name to get a short auto-generated default name
  3. If a long label is needed, store the long identifier separately and reference the short keypair name

Example fix

// before
run_generate("my-team-production-cluster-eu-west-1-keypair-2026")?
// after
run_generate("prod-eu1")?
Defensive patterns

Strategy: validation

Validate before calling

fn valid_keypair_name(name: &str) -> bool {
    const MAX_NAME_LEN: usize = 64; // match the CLI's MAX_NAME_LEN
    !name.is_empty() && name.len() <= MAX_NAME_LEN
}

Type guard

fn is_short_enough(name: &str, max: usize) -> bool { name.len() <= max }

Try / catch

match run_generate(&name) {
    Err(e) if e.to_string().contains("at most") => eprintln!("name too long, pick a shorter name"),
    other => other,
}

Prevention

When it happens

Trigger: Calling `aos keypair generate`, `show`, `pubkey`, or `delete` (or loading a public key / recording a binding) with a name whose byte length exceeds MAX_NAME_LEN.

Common situations: Copy-pasting a long host or project name as the keypair name; generating names programmatically by concatenating prefix + timestamp/uuid; CI configs embedding full hostnames.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09). Data as JSON: /api/errors/eacce3257a63c8cb. Report an issue: GitHub.

Appendix: source

Thrown at crates/astrid-cli/src/commands/keypair.rs:580

        match read_meta(&paths) {
            Ok(meta) => out.push(KeyEntry { name, meta }),
            Err(e) => {
                tracing::warn!(name = %name, error = %e, "skipping unreadable keypair meta");
            },
        }
    }
    out.sort_by(|a, b| a.name.cmp(&b.name));
    Ok(out)
}

// ── Misc helpers ─────────────────────────────────────────────────

fn validate_name(name: &str) -> Result<()> {
    if name.is_empty() {
        bail!("keypair name must not be empty");
    }
    if name.len() > MAX_NAME_LEN {
        bail!(
            "keypair name must be at most {MAX_NAME_LEN} chars (got {})",
            name.len()
        );
    }
    // Lowercase letters, digits, dash. Same posture as principal ids;
    // also avoids path-separator / shell-meta surprises.
    if !name
        .chars()
        .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-')
    {
        bail!("keypair name {name:?} contains invalid chars; only a-z, 0-9, '-' are allowed");
    }
    Ok(())
}

fn default_name() -> String {
    let mut bytes = [0u8; 4];
    SysRng

View on GitHub (pinned to affd8760f4)