{"record":{"id":"4c5fe70dd5932c41","repo":"gitbutlerapp/gitbutler","slug":"could-not-get-app-cache-dir","errorCode":null,"errorMessage":"Could not get app cache dir","messagePattern":"Could not get app cache dir","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-path/src/lib.rs","lineNumber":142,"sourceCode":"/// the compile-time or explicit channel.\n///\n/// # Errors\n///\n/// Returns an error if the platform's cache directory cannot be determined.\npub fn app_cache_dir() -> anyhow::Result<PathBuf> {\n    app_cache_dir_for_channel(AppChannel::new())\n}\n\n/// Like [`app_cache_dir()`], but explicitly for `channel`.\n///\n/// When `E2E_TEST_APP_DATA_DIR` is set, `channel` is ignored and the result is always\n/// `<E2E_TEST_APP_DATA_DIR>/cache`.\npub fn app_cache_dir_for_channel(channel: AppChannel) -> anyhow::Result<PathBuf> {\n    if let Some(test_dir) = std::env::var_os(\"E2E_TEST_APP_DATA_DIR\") {\n        return Ok(PathBuf::from(test_dir).join(\"cache\"));\n    }\n    dirs::cache_dir()\n        .ok_or(anyhow::anyhow!(\"Could not get app cache dir\"))\n        .map(|dir| dir.join(identifier_for_channel(channel)))\n}\n\n/// Returns the bundle identifier for the compile-time [`AppChannel`].\npub fn identifier() -> &'static str {\n    identifier_for_channel(AppChannel::new())\n}\n\n/// Returns the bundle identifier used for `channel`.\npub const fn identifier_for_channel(channel: AppChannel) -> &'static str {\n    match channel {\n        AppChannel::Nightly => \"com.gitbutler.app.nightly\",\n        AppChannel::Release => \"com.gitbutler.app\",\n        AppChannel::Dev => \"com.gitbutler.app.dev\",\n    }\n}\n\n/// A way to learn about the currently configured compile-time app-channel.","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but-path/src/lib.rs#L124-L160","documentation":"`app_cache_dir_for_channel` returns this when `dirs::cache_dir()` is None — no platform cache directory could be determined. On Linux this requires `XDG_CACHE_HOME` or a resolvable home dir (`$HOME/.cache` fallback); on macOS it needs a home dir. Setting `E2E_TEST_APP_DATA_DIR` returns `<test_dir>/cache` before this check runs.","triggerScenarios":"App or `but` binary running where HOME is unset and passwd lookup fails: minimal containers, systemd services without HOME, scrubbed cron environments. Also tooling that clears env vars for sandboxing.","commonSituations":"Headless CI, dockerized usage of the GitButler crates, launchd/systemd units missing environment configuration, portable/readonly-root environments.","solutions":["Set `HOME` or `XDG_CACHE_HOME` to a writable location in that environment","Set `E2E_TEST_APP_DATA_DIR` in test/CI contexts to get a deterministic cache path","Configure the service unit with an explicit HOME (e.g. `Environment=\"HOME=/var/cache/gitbutler\"`)","Treat cache-dir failure as non-fatal where possible: log and continue without cacheable features (update checks) instead of aborting startup"],"exampleFix":"// before\nlet dir = but_path::app_cache_dir()?; // Could not get app cache dir\n\n// after (degrade gracefully — cache is non-essential)\nlet cache = match but_path::app_cache_dir() {\n    Ok(dir) => Some(dir),\n    Err(e) => {\n        log::warn!(\"no cache dir ({e:#}); skipping cached features\");\n        None\n    }\n};","handlingStrategy":"fallback","validationCode":"fn cache_dir_available() -> bool {\n    std::env::var_os(\"XDG_CACHE_HOME\").is_some() || dirs::home_dir().is_some()\n}","typeGuard":null,"tryCatchPattern":"let cache = match but_path::app_cache_dir() {\n    Ok(dir) => Some(dir),\n    Err(e) => {\n        log::warn!(\"no cache dir; cached features disabled ({e:#})\");\n        None // cache is non-essential by design\n    }\n};","preventionTips":["Treat cache-dir failure as degradation, not fatal — the docs mark cache data as regenerable","Set HOME/XDG_CACHE_HOME in service units","Use E2E_TEST_APP_DATA_DIR to make cache paths deterministic under test"],"tags":["rust","filesystem","environment","dirs","cache"],"backgroundTag":"home-directory-not-found","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}