{"record":{"id":"8a7f76b9d4a446ca","repo":"Hmbown/CodeWhale","slug":"overwrite","errorCode":null,"errorMessage":"overwrite","messagePattern":"overwrite","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/release/src/check.rs","lineNumber":233,"sourceCode":"    #[test]\n    fn store_then_load_round_trips_and_survives_an_existing_file() {\n        let dir = tempfile::tempdir().expect(\"tempdir\");\n        let path = cache_path_in(dir.path());\n        assert_eq!(path.file_name().unwrap(), UPDATE_CHECK_CACHE_FILE);\n\n        let first = UpdateCheckCache {\n            checked_at_unix: 42,\n            latest_tag: Some(\"v0.9.5\".to_string()),\n        };\n        first.store(&path).expect(\"store\");\n        assert_eq!(UpdateCheckCache::load(&path), Some(first));\n\n        // Overwriting in place must not leave the temp file behind.\n        let second = UpdateCheckCache {\n            checked_at_unix: 99,\n            latest_tag: None,\n        };\n        second.store(&path).expect(\"overwrite\");\n        assert_eq!(UpdateCheckCache::load(&path), Some(second));\n        assert!(!path.with_extension(\"json.tmp\").exists());\n    }\n\n    #[test]\n    fn store_creates_a_missing_home_directory() {\n        let dir = tempfile::tempdir().expect(\"tempdir\");\n        let path = cache_path_in(&dir.path().join(\"nested\").join(\"home\"));\n        UpdateCheckCache::now(Some(\"v1.0.0\".to_string()))\n            .store(&path)\n            .expect(\"store into a fresh directory\");\n        assert!(path.exists());\n    }\n\n    #[test]\n    fn a_corrupt_or_absent_cache_reads_as_none() {\n        let dir = tempfile::tempdir().expect(\"tempdir\");\n        let path = cache_path_in(dir.path());","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/release/src/check.rs#L215-L251","documentation":"Test panic from `second.store(&path).expect(\"overwrite\")`: the second, in-place overwrite of the update-check cache failed. store writes to a `.json.tmp` sibling and renames over the existing file, so an overwrite failure means the temp write or the rename over the existing file errored — the atomic-replace path, not first-time creation.","triggerScenarios":"Calling store on a path where the target file already exists and the rename fails (file locked by another process, permission change after the first store, filesystem without atomic rename-over support, or the stale json.tmp left by a crashed run blocking the write).","commonSituations":"Tests run on network mounts (NFS/SMB) with unreliable rename-over-existing; leftover .json.tmp files from interrupted runs on shared TMPDIRs; concurrent test runs writing the same cache path.","solutions":["Check for and remove a stale `path.with_extension(\"json.tmp\")` before storing, since a leftover temp file can interfere.","Confirm the filesystem supports rename-over-existing atomically; prefer a local tmpfs for tests if running on NFS.","Inspect the anyhow context on the Err to see whether fs::write of the temp file or the rename step failed, and fix the underlying cause (permissions, locks, space)."],"exampleFix":"// before\nsecond.store(&path).expect(\"overwrite\");\n// after — tolerate or clean a stale temp file from a previous crashed run\nlet tmp = path.with_extension(\"json.tmp\");\nlet _ = std::fs::remove_file(&tmp);\nsecond.store(&path).expect(\"overwrite\");","handlingStrategy":"fallback","validationCode":"// clear a stale temp file that can block the overwrite\nlet tmp = path.with_extension(\"json.tmp\");\nif tmp.exists() { let _ = std::fs::remove_file(&tmp); }","typeGuard":"fn can_replace(p: &Path) -> bool {\n    p.parent().map(|d| writable_dir(d)).unwrap_or(false)\n}\nfn writable_dir(p: &Path) -> bool {\n    p.metadata().map(|m| !m.permissions().readonly()).unwrap_or(false)\n}","tryCatchPattern":"match second.store(&path) {\n    Ok(()) => {},\n    Err(e) => eprintln!(\"cache overwrite failed, continuing without cache: {e:#}\"),\n}","preventionTips":["Always write-then-rename atomically so a failed overwrite never corrupts the existing cache.","Clean up leftover *.tmp files on startup; a crashed run can strand them.","Avoid shared/network filesystems for cache paths; prefer a per-user local directory."],"tags":["rust","filesystem","atomic-write","rename","test-panic"],"backgroundTag":"file-write-failed","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}