{"record":{"id":"315d203108e2a542","repo":"pot-app/pot-desktop","slug":"get-cache-dir-failed-315d20","errorCode":null,"errorMessage":"Get Cache Dir Failed","messagePattern":"Get Cache Dir Failed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/src/screenshot.rs","lineNumber":16,"sourceCode":"use log::info;\n\n#[tauri::command]\npub fn screenshot(x: i32, y: i32) {\n    use crate::APP;\n    use dirs::cache_dir;\n    use screenshots::{Compression, Screen};\n    use std::fs;\n    info!(\"Screenshot screen with position: x={}, y={}\", x, y);\n    let screens = Screen::all().unwrap();\n    for screen in screens {\n        let info = screen.display_info;\n        info!(\"Screen: {:?}\", info);\n        if info.x == x && info.y == y {\n            let handle = APP.get().unwrap();\n            let mut app_cache_dir_path = cache_dir().expect(\"Get Cache Dir Failed\");\n            app_cache_dir_path.push(&handle.config().tauri.bundle.identifier);\n            if !app_cache_dir_path.exists() {\n                // 创建目录\n                fs::create_dir_all(&app_cache_dir_path).expect(\"Create Cache Dir Failed\");\n            }\n            app_cache_dir_path.push(\"pot_screenshot.png\");\n\n            let image = screen.capture().unwrap();\n            let buffer = image.to_png(Compression::Fast).unwrap();\n            fs::write(app_cache_dir_path, buffer).unwrap();\n            break;\n        }\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/pot-app/pot-desktop/blob/594d32ede96acd106b0256deaa8bb440ffcdff40/src-tauri/src/screenshot.rs#L1-L31","documentation":"In the screenshot command, dirs::cache_dir() returned None and .expect('Get Cache Dir Failed') panicked. cache_dir() yields None when the OS provides no cache directory (e.g. missing/invalid XDG_CACHE_HOME on Linux, or unavailable user profile on Windows), so no path exists where the screenshot cut image can be stored.","triggerScenarios":"Thrown at src-tauri/src/screenshot.rs:16 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the environment provides a cache dir (set XDG_CACHE_HOME/HOME correctly on Linux; check user profile on Windows)","Fall back to std::env::temp_dir() when cache_dir() is None instead of panicking","Convert the command to return Result and report the failure to the frontend rather than crashing the process"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"594d32ede96acd106b0256deaa8bb440ffcdff40","analyzedAt":"2026-09-02T18:12:21.811Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}