pot-app/pot-desktop · error
Get Cache Dir Failed
Error message
Get Cache Dir Failed
What it means
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.
Source
Thrown at src-tauri/src/screenshot.rs:16
use log::info;
#[tauri::command]
pub fn screenshot(x: i32, y: i32) {
use crate::APP;
use dirs::cache_dir;
use screenshots::{Compression, Screen};
use std::fs;
info!("Screenshot screen with position: x={}, y={}", x, y);
let screens = Screen::all().unwrap();
for screen in screens {
let info = screen.display_info;
info!("Screen: {:?}", info);
if info.x == x && info.y == y {
let handle = APP.get().unwrap();
let mut app_cache_dir_path = cache_dir().expect("Get Cache Dir Failed");
app_cache_dir_path.push(&handle.config().tauri.bundle.identifier);
if !app_cache_dir_path.exists() {
// 创建目录
fs::create_dir_all(&app_cache_dir_path).expect("Create Cache Dir Failed");
}
app_cache_dir_path.push("pot_screenshot.png");
let image = screen.capture().unwrap();
let buffer = image.to_png(Compression::Fast).unwrap();
fs::write(app_cache_dir_path, buffer).unwrap();
break;
}
}
}
View on GitHub (pinned to 594d32ede9)
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
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at src-tauri/src/screenshot.rs:16 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of pot-app/pot-desktop@594d32ede9 (2026-09-02).
Data as JSON: /api/errors/315d203108e2a542.
Report an issue: GitHub.