{"record":{"id":"1f59e911c30e76ba","repo":"tracel-ai/burn","slug":"failed-to-create-cache-directory-1f59e9","errorCode":null,"errorMessage":"Failed to create cache directory","messagePattern":"Failed to create cache directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-train/src/metric/vision/fid/weights.rs","lineNumber":18,"sourceCode":"use burn_std::network::downloader::download_file_as_bytes;\nuse burn_store::{ModuleSnapshot, PytorchStore};\nuse std::fs::{File, create_dir_all};\nuse std::io::Write;\nuse std::path::PathBuf;\n\nuse super::metric::Fid;\n\nconst INCEPTION_WEIGHTS_URL: &str = \"https://github.com/mseitzer/pytorch-fid/releases/download/fid_weights/pt-inception-2015-12-05-6726825d.pth\";\n\nfn get_cache_dir() -> PathBuf {\n    let cache_dir = dirs::cache_dir()\n        .expect(\"Could not get cache directory\")\n        .join(\"burn-dataset\")\n        .join(\"fid\");\n\n    if !cache_dir.exists() {\n        create_dir_all(&cache_dir).expect(\"Failed to create cache directory\");\n    }\n\n    cache_dir\n}\n\nfn download_if_needed(url: &str, cache_path: &PathBuf, message: &str) {\n    if !cache_path.exists() {\n        let bytes = download_file_as_bytes(url, message);\n        let mut file = File::create(cache_path).expect(\"Failed to create cache file\");\n        file.write_all(&bytes).expect(\"Failed to write weights\");\n    }\n}\n\n/// Download and load pretrained pytorch-fid InceptionV3 weights.\n///\n/// Weights are cached in `~/.cache/burn-dataset/fid/`.\npub fn load_pretrained_weights(mut fid: Fid) -> Fid {\n    let cache_dir = get_cache_dir();","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-train/src/metric/vision/fid/weights.rs#L1-L36","documentation":"In the FID weights module, `get_cache_dir()` panics via `create_dir_all(&cache_dir).expect(\"Failed to create cache directory\")` when `~/.cache/burn-dataset/fid` cannot be created. The cache root resolved fine, but mkdir failed — permissions, read-only filesystem, quota, or a non-directory file at the target path. This blocks FID `load_pretrained_weights` before the Inception download begins.","triggerScenarios":"First FID `load_pretrained_weights` call when the fid cache dir is missing and `create_dir_all` fails: `~/.cache` not writable, root-owned `burn-dataset` from an earlier root run, read-only rootfs, or a stale file named `fid` in `burn-dataset`.","commonSituations":"User mismatch between cache creator and runner; immutable container images without a writable cache volume mount; quotas on home directories; leftovers colliding with the cache path.","solutions":["Repair permissions: `mkdir -p ~/.cache/burn-dataset && chown -R $(whoami) ~/.cache/burn-dataset`","Remove a colliding non-directory file at `~/.cache/burn-dataset/fid`","Redirect via `XDG_CACHE_HOME` to a writable, pre-created directory","In containerized deployments, mount an emptyDir/volume at the cache path and run as a consistent user"],"exampleFix":"// before (Dockerfile)\nUSER 1000\nCMD [\"./trainer\"]\n// after (Dockerfile)\nENV XDG_CACHE_HOME=/home/app/.cache\nRUN mkdir -p /home/app/.cache/burn-dataset/fid && chown -R 1000 /home/app/.cache\nUSER 1000\nCMD [\"./trainer\"]","handlingStrategy":"validation","validationCode":"let fid_dir = dirs::cache_dir().unwrap().join(\"burn-dataset\").join(\"fid\");\nstd::fs::create_dir_all(&fid_dir).expect(\"cannot prepare fid cache dir\");\nif fid_dir.exists() && !fid_dir.is_dir() {\n    eprintln!(\"{} blocks the cache dir; remove it\", fid_dir.display());\n}","typeGuard":"fn cache_dir_writable(dir: &std::path::Path) -> bool {\n    dir.is_dir() && std::fs::write(dir.join(\".probe\"), b\"\").is_ok()\n}","tryCatchPattern":"let weights = std::panic::catch_unwind(load_pretrained_weights)\n    .map_err(|_| anyhow!(\"fid cache dir creation failed; check ~/.cache permissions\"))?;","preventionTips":["Pre-create ~/.cache/burn-dataset/fid during setup with correct ownership","Avoid mixing root and non-root runs against the same home cache","Mount writable volumes when the rootfs is read-only","Remove non-directory files that collide with the cache path before running"],"tags":["panic","filesystem","permissions","cache-dir"],"backgroundTag":"cache-dir-unavailable","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}