Hmbown/CodeWhale · error

store

Error message

store

What it means

Test panic from `first.store(&path).expect("store")`: UpdateCheckCache::store failed to persist the cache file. store creates the parent directory, writes a `json.tmp` temp file, then renames it into place; the expect fires when any of create_dir_all, fs::write, or rename returns an Err carrying its anyhow context.

Solutions

  1. Read the anyhow context message from the panic/backtrace ("failed to create …", "failed to write …", "failed to install …") to identify which of the three steps failed.
  2. Ensure the test's tempdir parent is writable; check permissions and free space on the backing filesystem.
  3. If rename fails because the target is held open, close competing handles or retry; on exotic filesystems verify rename support for the tempdir location.

Example fix

// before
first.store(&path).expect("store");
// after — surface which step failed when debugging
if let Err(e) = first.store(&path) {
    panic!("store failed: {e:#}"); // prints create/write/install context chain
}
Defensive patterns

Strategy: try-catch

Validate before calling

// verify the target directory is writable before storing
let dir = path.parent().unwrap();
assert!(dir.exists() && !dir.metadata().unwrap().permissions().readonly());

Type guard

fn writable_dir(p: &Path) -> bool {
    p.metadata().map(|m| !m.permissions().readonly()).unwrap_or(false)
}

Try / catch

entry.store(&path).unwrap_or_else(|e| panic!("cache store failed: {e:#}")); // anyhow context chain shows create/write/install step

Prevention

When it happens

Trigger: Calling UpdateCheckCache::store on a path whose parent cannot be created (permission denied), whose temp file cannot be written (full disk, read-only mount), or whose rename target is locked/blocked (e.g. cross-filesystem rename after some environments make the .tmp path behave unexpectedly).

Common situations: Running tests on a read-only home or filesystem; disk full; antivirus/backup tools holding the target file open so rename fails; nested-home edge cases where create_dir_all hits a permission wall.

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 Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/3e021dcaf791e2fe. Report an issue: GitHub.

Appendix: source

Thrown at crates/release/src/check.rs:225

    fn a_future_timestamp_is_stale_not_permanently_fresh() {
        let entry = UpdateCheckCache {
            checked_at_unix: 2_000_000,
            latest_tag: Some("v9.9.9".to_string()),
        };
        assert!(!entry.is_fresh(1_000_000, 24));
    }

    #[test]
    fn store_then_load_round_trips_and_survives_an_existing_file() {
        let dir = tempfile::tempdir().expect("tempdir");
        let path = cache_path_in(dir.path());
        assert_eq!(path.file_name().unwrap(), UPDATE_CHECK_CACHE_FILE);

        let first = UpdateCheckCache {
            checked_at_unix: 42,
            latest_tag: Some("v0.9.5".to_string()),
        };
        first.store(&path).expect("store");
        assert_eq!(UpdateCheckCache::load(&path), Some(first));

        // Overwriting in place must not leave the temp file behind.
        let second = UpdateCheckCache {
            checked_at_unix: 99,
            latest_tag: None,
        };
        second.store(&path).expect("overwrite");
        assert_eq!(UpdateCheckCache::load(&path), Some(second));
        assert!(!path.with_extension("json.tmp").exists());
    }

    #[test]
    fn store_creates_a_missing_home_directory() {
        let dir = tempfile::tempdir().expect("tempdir");
        let path = cache_path_in(&dir.path().join("nested").join("home"));
        UpdateCheckCache::now(Some("v1.0.0".to_string()))
            .store(&path)

View on GitHub (pinned to 433685b202)