lencx/ChatGPT · error

[view:download] Failed to get download directory

Error message

[view:download] Failed to get download directory

What it means

Panic from app_handle.path().download_dir() (tauri::path resolver, backed by the dirs crate) returning Err. The resolver fails when the OS cannot determine the user's download directory: on Linux XDG_DOWNLOAD_DIR is undefined in the user-dirs config, on Windows the known-folder API fails, or the app is sandboxed without the download folder entitlement. This runs inside the WebviewBuilder::on_download callback, so the panic kills the download request handling.

Source

Thrown at src-tauri/src/core/setup.rs:68

            let win_size = core_window
                .inner_size()
                .expect("[core:window] Failed to get window size");
            // Wrap the window in Arc<Mutex<_>> to manage ownership across threads
            let window = Arc::new(Mutex::new(core_window));

            let main_view =
                WebviewBuilder::new("main", WebviewUrl::App("https://chatgpt.com".into()))
                    .auto_resize()
                    .on_download({
                        let app_handle = handle.clone();
                        let download_path = Arc::new(Mutex::new(PathBuf::new()));
                        move |_, event| {
                            match event {
                                DownloadEvent::Requested { destination, .. } => {
                                    let download_dir = app_handle
                                        .path()
                                        .download_dir()
                                        .expect("[view:download] Failed to get download directory");
                                    let mut locked_path = download_path
                                        .lock()
                                        .expect("[view:download] Failed to lock download path");
                                    *locked_path = download_dir.join(&destination);
                                    *destination = locked_path.clone();
                                }
                                DownloadEvent::Finished { success, .. } => {
                                    let final_path = download_path
                                        .lock()
                                        .expect("[view:download] Failed to lock download path")
                                        .clone();

                                    if success {
                                        app_handle
                                            .shell()
                                            .open(final_path.to_string_lossy(), None)
                                            .expect("[view:download] Failed to open file");
                                    }

View on GitHub (pinned to a6de9a8b61)

Solutions

  1. Use .ok()/if-let and keep the webview-provided default destination instead of redirecting to the download dir, logging a warning
  2. Fall back to an explicit directory, e.g. dirs-style resolution order: download_dir() -> home_dir()/Downloads -> temp dir
  3. On Linux install xdg-user-dirs (or ensure ~/.config/user-dirs.dirs defines XDG_DOWNLOAD_DIR) and confirm $HOME is set when launching
  4. In sandboxed packaging (flatpak/AppImage), grant the download folder permission

Example fix

// before
let download_dir = app_handle
    .path()
    .download_dir()
    .expect("[view:download] Failed to get download directory");

// after
let Some(download_dir) = app_handle.path().download_dir().ok() else {
    eprintln!("[view:download] download_dir unavailable; keeping default destination");
    return true;
};
Defensive patterns

Strategy: fallback

Validate before calling

// probe before the download ever starts, e.g. during setup
if app_handle.path().download_dir().is_err() {
    eprintln!("[view:download] download_dir unresolvable; downloads will use default destination");
}

Type guard

fn resolve_download_dir(handle: &tauri::AppHandle) -> Option<std::path::PathBuf> {
    handle.path().download_dir().ok()
}

Try / catch

let Some(download_dir) = app_handle.path().download_dir().ok() else {
    eprintln!("[view:download] download_dir unavailable");
    return true; // allow download with webview default destination
};

Prevention

When it happens

Trigger: A DownloadEvent::Requested fires (user clicks a download link in the chatgpt.com webview) while download_dir() cannot resolve: minimal Linux distro without xdg-user-dirs installed, XDG_CONFIG_HOME/user-dirs.dirs missing the XDG_DOWNLOAD_DIR line, macOS sandbox/app-translocation blocking the path, HOME unset in the environment.

Common situations: Running the app from a clean container/CI or a barebones WM (no xdg-user-dirs); launching via systemd/ssh where HOME or XDG vars are absent; flatpak/sandbox packaging without filesystem permissions; changing the download location in OS settings to an unavailable volume.

Related errors


AI-assisted analysis of lencx/ChatGPT@a6de9a8b61 (2026-08-16). Data as JSON: /api/errors/ce62e266cc6f0ed6. Report an issue: GitHub.