astrid-runtime/astrid · error

keypair name must not be empty

Error message

keypair name must not be empty

What it means

`validate_name` rejects an empty keypair name before any file operations. Names are used to build key file paths, so an empty string would produce invalid paths; this is the first of several name checks (length, charset).

Source

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

            public_hex: dir.join(format!("{name}.pub.hex")),
            meta: path,
        };
        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(())
}

View on GitHub (pinned to affd8760f4)

Solutions

  1. Pass a non-empty keypair name.
  2. Omit --name entirely to use the default keypair name for generate.
  3. Fix the shell variable/script so the name is set before invocation.
  4. Validate inputs in automation before calling astrid.

Example fix

// before
astrid keypair show "$KP_NAME"   # KP_NAME empty
// after
: "${KP_NAME:?KP_NAME must be set}"
astrid keypair show "$KP_NAME"
Defensive patterns

Strategy: validation

Validate before calling

[ -n "$KP_NAME" ] || { echo "keypair name required" >&2; exit 2; }

Prevention

When it happens

Trigger: Calling keypair commands with --name "" or an argument that resolves to empty (e.g. an unset shell variable expanded to nothing), or code paths like load_public_key_hex/record_binding receiving an empty name.

Common situations: Shell scripts with unset variables: `--name "$KP_NAME"` where KP_NAME is empty; mis-parsed CLI args; programmatic callers passing an empty string.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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