astrid-runtime/astrid · error

non-empty audit

Error message

non-empty audit

What it means

Panic from `std::fs::write(other_home.audit_dir().join("entry"), b"audit").expect("non-empty audit")`. The test writes a sentinel audit entry file to make the legacy audit directory non-empty; the expect fires when the file write fails.

Source

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

        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. Ensure the principal home (and thus audit dir) is created before writing the entry file.
  2. Check permissions and disk space on the temp filesystem.
  3. Verify `audit_dir()` points where expected (print the path) — a path mismatch is a common cause.
  4. Handle the io::Error explicitly instead of expect in non-test code.

Example fix

// before
std::fs::write(other_home.audit_dir().join("entry"), b"audit").expect("non-empty audit");
// after
std::fs::create_dir_all(other_home.audit_dir()).expect("audit dir");
std::fs::write(other_home.audit_dir().join("entry"), b"audit").unwrap_or_else(|e| panic!("non-empty audit: {e}"));
Defensive patterns

Strategy: validation

Validate before calling

let dir = other_home.audit_dir();
std::fs::create_dir_all(&dir)?;
assert!(dir.is_dir(), "audit dir missing before write");

Try / catch

std::fs::write(path, b"audit")
    .unwrap_or_else(|e| panic!("audit entry write failed: {e}"));

Prevention

When it happens

Trigger: Writing to `audit_dir/entry` when the audit directory does not exist (ensure not yet run), permissions deny write, or the path resolves to a directory named `entry`.

Common situations: Ordering mistakes where the audit dir isn't created before the write, read-only CI filesystems, or disk-full conditions during large test suites.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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