gitbutlerapp/gitbutler · error

Could not get app data dir

Error message

Could not get app data dir

What it means

Thrown by `app_data_dir_for_channel` when `dirs::data_dir()` returns None, meaning the platform's user data directory cannot be determined. On Linux this happens when XDG_DATA_HOME is unset and $HOME is also unset/unresolvable, so there is no base directory under which to build `<data>/com.gitbutler.app`.

Solutions

  1. Ensure HOME is set and points to a writable directory (export HOME=/home/user)
  2. Set XDG_DATA_HOME explicitly (e.g. export XDG_DATA_HOME=$HOME/.local/share)
  3. In containers, create the user/home before running the app (useradd or -e HOME=/tmp)
  4. For tests, set E2E_TEST_APP_DATA_DIR to a writable path to bypass the platform lookup

Example fix

// before (Docker)
CMD ["but", ...]  // HOME unset

// after
ENV HOME=/home/but
CMD ["but", ...]
Defensive patterns

Strategy: try-catch

Validate before calling

// caller pre-check
if std::env::var_os("HOME").is_none()
    && std::env::var_os("XDG_DATA_HOME").is_none()
    && std::env::var_os("E2E_TEST_APP_DATA_DIR").is_none()
{
    eprintln!("Set HOME or XDG_DATA_HOME before starting");
}

Try / catch

match app_data_dir() {
    Err(e) if e.to_string().contains("app data dir") => {
        eprintln!("No user data dir available: set HOME/XDG_DATA_HOME");
    }
    r => r?,
}

Prevention

When it happens

Trigger: Calling `app_data_dir_for_channel(channel)` (directly or via `app_data_dir`) on a system where `dirs::data_dir()` yields None — typically Linux with no HOME and no XDG_DATA_HOME; E2E_TEST_APP_DATA_DIR override not set.

Common situations: Running the app or CLI in a bare Docker container without HOME set; systemd services with a sanitized environment; cron jobs lacking HOME; headless CI runners with minimal env.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/4c9f76f7a6a21d95. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-path/src/lib.rs:55

/// When `E2E_TEST_APP_DATA_DIR` is set, returns `<E2E_TEST_APP_DATA_DIR>/home`
/// so tests never touch the real home directory.
pub fn home_dir() -> Option<PathBuf> {
    if let Some(test_dir) = std::env::var_os("E2E_TEST_APP_DATA_DIR") {
        return Some(PathBuf::from(test_dir).join("home"));
    }
    dirs::home_dir()
}

/// Like [`app_data_dir()`], but explicitly for `channel`.
///
/// When `E2E_TEST_APP_DATA_DIR` is set, `channel` is ignored and the result is always
/// `<E2E_TEST_APP_DATA_DIR>/com.gitbutler.app`.
pub fn app_data_dir_for_channel(channel: AppChannel) -> anyhow::Result<PathBuf> {
    if let Some(test_dir) = std::env::var_os("E2E_TEST_APP_DATA_DIR") {
        return Ok(PathBuf::from(test_dir).join("com.gitbutler.app"));
    }
    dirs::data_dir()
        .ok_or(anyhow::anyhow!("Could not get app data dir"))
        .map(|dir| dir.join(identifier_for_channel(channel)))
}

/// The directory to store logs in, **one per channel**.
///
/// > ⚠️Keep in sync with `tauri::AppHandle::path().app_log_dir().`
///
/// # Platform-specific locations
///
/// - **macOS**: `~/Library/Logs/<identifier()>`
/// - **Linux/Windows/other**: `<data_local_dir>/<identifier()>/logs`
///
/// # Testing behavior
///
/// When the `E2E_TEST_APP_DATA_DIR` environment variable is set (used by E2E tests),
/// this function returns `<E2E_TEST_APP_DATA_DIR>/logs` instead of the platform-specific
/// default directories above. This override always ignores the compile-time channel.
pub fn app_log_dir() -> anyhow::Result<PathBuf> {

View on GitHub (pinned to 58e5313667)