Hmbown/CodeWhale · error

write junk

Error message

write junk

What it means

Test panic from `std::fs::write(&path, b"{ not json").expect("write junk")`: the test could not write its deliberately corrupt cache fixture to disk. This is a raw std::fs::write failure inside the test, independent of the library's own store logic.

Solutions

  1. Ensure tests do not share a fixed TMPDIR path concurrently; use a unique tempdir per run.
  2. Check filesystem permissions and free space at the temp location.
  3. Look for file-locking agents (AV, sync clients) on the machine and exclude the temp directory from scanning.

Example fix

// before
std::fs::write(&path, b"{ not json").expect("write junk");
// after — verify the directory still exists before writing
assert!(path.parent().map(|d| d.exists()).unwrap_or(false));
std::fs::write(&path, b"{ not json").expect("write junk");
Defensive patterns

Strategy: validation

Validate before calling

// confirm the fixture path is writable before writing the junk payload
assert!(path.parent().map(|d| d.exists()).unwrap_or(false), "fixture dir vanished mid-test");

Type guard

fn writable_file(p: &Path) -> bool {
    p.metadata().map(|m| !m.permissions().readonly()).unwrap_or(true) // absent files are writable if the dir is
}

Try / catch

std::fs::write(&path, b"{ not json")
    .unwrap_or_else(|e| panic!("could not write corrupt-cache fixture: {e}"));

Prevention

When it happens

Trigger: Calling std::fs::write on the cache path inside the tempdir: fails when the file exists but is not writable (permission change), the directory was removed mid-test, the disk filled, or another process holds the path exclusively locked.

Common situations: Shared TMPDIR with concurrent test runs deleting each other's directories; antivirus/backup software locking newly created files; read-only remounts or quota exhaustion during a test run.

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/88836b837427ccc6. Report an issue: GitHub.

Appendix: source

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

        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)
            .expect("store into a fresh directory");
        assert!(path.exists());
    }

    #[test]
    fn a_corrupt_or_absent_cache_reads_as_none() {
        let dir = tempfile::tempdir().expect("tempdir");
        let path = cache_path_in(dir.path());
        assert_eq!(UpdateCheckCache::load(&path), None);
        std::fs::write(&path, b"{ not json").expect("write junk");
        assert_eq!(UpdateCheckCache::load(&path), None);
    }

    #[test]
    fn falsey_flag_values_do_not_count_as_set() {
        for value in ["", "0", "false", "FALSE", " no ", "off"] {
            assert!(
                !flag_value_is_truthy(value),
                "{value:?} should not read as set"
            );
        }
        for value in ["1", "true", "yes", "azure-pipelines"] {
            assert!(flag_value_is_truthy(value), "{value:?} should read as set");
        }
    }

    #[test]
    fn suppression_reason_names_the_responsible_variable() {

View on GitHub (pinned to 433685b202)