astrid-runtime/astrid · error

principal id

Error message

principal id

What it means

Panic from `astrid_core::PrincipalId::new("other".to_owned()).expect("principal id")`. `PrincipalId::new` validates the supplied string and returns Err for identifiers that violate the principal-id rules (e.g. empty, illegal characters, or overly long). The expect message means the string was not accepted as a valid principal id.

Source

Thrown at crates/astrid-kernel/src/audit_retirement_tests.rs:70

    require_audit_integrity(&valid).expect("valid history is accepted by the derived helper");

    let invalid = vec![(
        SessionId::new(),
        ChainVerificationResult {
            valid: false,
            entries_verified: 1,
            issues: Vec::new(),
        },
    )];
    assert!(require_audit_integrity(&invalid).is_err());
}

#[test]
fn audit_boot_rejects_unhandled_non_default_source() {
    let directory = tempfile::tempdir().expect("temporary home");
    let home = AstridHome::from_path(directory.path().join(".astrid"));
    home.ensure().expect("home layout");
    let other = astrid_core::PrincipalId::new("other".to_owned()).expect("principal id");
    let other_home = home.principal_home(&other);
    other_home.ensure().expect("legacy principal layout");
    std::fs::write(other_home.audit_dir().join("entry"), b"audit").expect("non-empty audit");
    let default_source = home
        .principal_home(&astrid_core::PrincipalId::default())
        .audit_dir();

    let error = preflight_legacy_audit_sources(&home, &default_source)
        .expect_err("unhandled non-empty source must block boot");
    assert!(
        error
            .to_string()
            .contains("only the default principal source")
    );
    assert!(other_home.audit_dir().exists());
    assert_eq!(
        std::fs::read(other_home.audit_dir().join("entry")).expect("preserved"),
        b"audit"

View on GitHub (pinned to affd8760f4)

Solutions

  1. Log/inspect the Err value from PrincipalId::new to see which validation rule the string violates.
  2. Ensure the input matches the accepted charset/format documented for PrincipalId (plain, non-empty, allowed characters).
  3. Update the test or caller to use a conforming identifier string.
  4. If validation changed intentionally, update PrincipalId::new call sites and fixtures to the new format.

Example fix

// before
let other = astrid_core::PrincipalId::new("other".to_owned()).expect("principal id");
// after
let other = astrid_core::PrincipalId::new("other".to_owned())
    .unwrap_or_else(|e| panic!("principal id rejected: {e}"));
Defensive patterns

Strategy: validation

Validate before calling

fn is_valid_principal_id(s: &str) -> bool {
    !s.is_empty() && s.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
}

Try / catch

let other = astrid_core::PrincipalId::new(input.to_owned())
    .map_err(|e| format!("invalid principal id: {e}"))?;

Prevention

When it happens

Trigger: Calling `PrincipalId::new` with a string that fails validation — empty string, whitespace, invalid characters, or a value exceeding the length limit. In this test the literal "other" is expected valid; a failure indicates the validator changed or the input deviates.

Common situations: Version drift where `PrincipalId::new` gained stricter validation after the test was written; copying the constructor pattern with user-controlled strings; passing an empty or formatted (non-plain) string.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


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