pot-app/pot-desktop · error

Get Cache Dir Failed

Error message

Get Cache Dir Failed

What it means

In the Windows-only system_ocr command, dirs::cache_dir() returned None and .expect('Get Cache Dir Failed') panicked before OCR can read the screenshot cut image. The system provides no cache directory (e.g. corrupted or missing user profile/environment), so the path to pot_screenshot_cut.png cannot be resolved.

Source

Thrown at src-tauri/src/system_ocr.rs:12

use dirs::cache_dir;

#[tauri::command(async)]
#[cfg(target_os = "windows")]
pub fn system_ocr(app_handle: tauri::AppHandle, lang: &str) -> Result<String, String> {
    use windows::core::HSTRING;
    use windows::Globalization::Language;
    use windows::Graphics::Imaging::BitmapDecoder;
    use windows::Media::Ocr::OcrEngine;
    use windows::Storage::{FileAccessMode, StorageFile};

    let mut app_cache_dir_path = cache_dir().expect("Get Cache Dir Failed");
    app_cache_dir_path.push(&app_handle.config().tauri.bundle.identifier);
    app_cache_dir_path.push("pot_screenshot_cut.png");

    let path = app_cache_dir_path.to_string_lossy().replace("\\\\?\\", "");

    let file = StorageFile::GetFileFromPathAsync(&HSTRING::from(path))
        .unwrap()
        .get()
        .unwrap();

    let bitmap = BitmapDecoder::CreateWithIdAsync(
        BitmapDecoder::PngDecoderId().unwrap(),
        &file.OpenAsync(FileAccessMode::Read).unwrap().get().unwrap(),
    )
    .unwrap()
    .get()
    .unwrap();

View on GitHub (pinned to 594d32ede9)

Solutions

  1. Verify the Windows user profile and LOCALAPPDATA environment variable are set correctly
  2. Fall back to std::env::temp_dir() when cache_dir() is None
  3. Change the command to return Result<String, String> and report the error to the frontend rather than panicking
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at src-tauri/src/system_ocr.rs:12 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/fc0ec63a21c1b0c5. Report an issue: GitHub.