{"record":{"id":"ca8ca64f20f0f32f","repo":"tracel-ai/burn","slug":"could-not-get-cache-directory-ca8ca6","errorCode":null,"errorMessage":"Could not get cache directory","messagePattern":"Could not get cache directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-train/src/metric/vision/lpips/weights.rs","lineNumber":47,"sourceCode":"        LpipsNet::Vgg => LPIPS_VGG_URL,\n        LpipsNet::Alex => LPIPS_ALEX_URL,\n        LpipsNet::Squeeze => LPIPS_SQUEEZE_URL,\n    }\n}\n\n/// Get the download URL for backbone ImageNet weights.\npub fn get_backbone_weights_url(net: LpipsNet) -> &'static str {\n    match net {\n        LpipsNet::Vgg => VGG16_IMAGENET_URL,\n        LpipsNet::Alex => ALEXNET_IMAGENET_URL,\n        LpipsNet::Squeeze => SQUEEZENET_IMAGENET_URL,\n    }\n}\n\n/// Get the cache directory for LPIPS weights.\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(\"lpips\");\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\n/// Download file if not cached and return the cache path.\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}","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-train/src/metric/vision/lpips/weights.rs#L29-L65","documentation":"Generic guard panic in get_cache_dir: dirs::cache_dir() returned None, meaning the platform cache directory could not be determined. On Linux this happens when XDG_CACHE_HOME is set but empty or non-absolute (or HOME is unavailable); on other platforms when the OS API for the user cache path fails. The faulty input is the environment/platform configuration, not the code's arguments. It surfaces when load_pretrained_weights tries to place downloaded LPIPS weights.","triggerScenarios":"Thrown at crates/burn-train/src/metric/vision/lpips/weights.rs:47 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure XDG_CACHE_HOME (Linux) or the user home directory is set","Run in an environment with a resolvable user cache dir","Override by providing weights manually if the environment lacks a cache dir"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}