{"record":{"id":"e0717d8fff16f1a7","repo":"janhq/jan","slug":"failed-to-determine-the-home-directory","errorCode":null,"errorMessage":"Failed to determine the home directory","messagePattern":"Failed to determine the home directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src-tauri/src/core/app/commands.rs","lineNumber":91,"sourceCode":"                paths.push(legacy);\n            }\n        }\n    }\n\n    paths\n}\n\nfn app_data_dir_with_fallback<R: Runtime>(app_handle: &tauri::AppHandle<R>) -> PathBuf {\n    let package_name = env!(\"CARGO_PKG_NAME\");\n    app_handle.path().data_dir().unwrap_or_else(|err| {\n        log::error!(\"Failed to get data directory: {err}. Using home directory instead.\");\n\n        let home_dir = std::env::var(if cfg!(target_os = \"windows\") {\n            \"USERPROFILE\"\n        } else {\n            \"HOME\"\n        })\n        .expect(\"Failed to determine the home directory\");\n\n        PathBuf::from(home_dir)\n    })\n    .join(package_name)\n}\n\n/// Resolve the Jan config file path without an AppHandle (for CLI use).\n/// Canonical location is `%APPDATA%/Jan/settings.json` (or OS equivalent),\n/// with fallback recovery from bundle-id location when needed.\npub fn resolve_config_file_path() -> PathBuf {\n    let app_data = resolve_human_readable_app_data_dir().unwrap_or_else(|| {\n        let package_name = env!(\"CARGO_PKG_NAME\");\n        let home = std::env::var(\"HOME\")\n            .or_else(|_| std::env::var(\"USERPROFILE\"))\n            .unwrap_or_default();\n        PathBuf::from(home).join(package_name)\n    });\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/janhq/jan/blob/fad3f12a147d138388a66f0d92a02b2675f65294/src-tauri/src/core/app/commands.rs#L73-L109","documentation":"This is a panic (.expect) that occurs only when Tauri's path().data_dir() already failed AND the HOME (Unix) or USERPROFILE (Windows) environment variable is also unset. It is the inner fallback of app_data_dir_with_fallback — the last resort for locating the app data directory. In normal desktop use this is unreachable; it triggers in stripped-down headless/container environments.","triggerScenarios":"Running the Tauri app inside a container without HOME set and without XDG_DATA_HOME. Launching via a systemd unit or cron job that does not inherit the user environment. Running as a service account whose HOME is deliberately unset. macOS app bundle launched in a sandbox that strips env vars.","commonSituations":"Docker containers running the desktop app without -e HOME=/home/user. CI environments running integration tests against the GUI binary. systemd services missing Environment=HOME=. Root user with HOME unset.","solutions":["Set the HOME environment variable (Unix) or USERPROFILE (Windows) before launching the app.","Set XDG_DATA_HOME on Linux to explicitly specify the data directory.","For systemd services, add `Environment=HOME=/var/lib/jan` to the unit file.","For Docker, pass `-e HOME=/home/jan -v /home/jan:/home/jan`."],"exampleFix":"# before (Docker)\ndocker run jan-app\n\n# after\ndocker run -e HOME=/home/jan -e XDG_DATA_HOME=/home/jan/.local/share jan-app","handlingStrategy":"validation","validationCode":"// Check env vars are set before relying on the fallback\nfn ensure_home_available() -> Result<(), String> {\n    let home = if cfg!(target_os = \"windows\") {\n        std::env::var(\"USERPROFILE\")\n    } else {\n        std::env::var(\"HOME\")\n    };\n    home.map(|_| ()).map_err(|_| {\n        \"Neither HOME nor the Tauri data_dir is available. Set HOME or XDG_DATA_HOME.\".to_string()\n    })\n}","typeGuard":null,"tryCatchPattern":"// Replace .expect with a graceful error\nlet home_dir = std::env::var(if cfg!(target_os = \"windows\") { \"USERPROFILE\" } else { \"HOME\" });\nlet home = match home_dir {\n    Ok(h) => PathBuf::from(h),\n    Err(_) => {\n        log::error!(\"HOME/USERPROFILE unset and data_dir failed; using /tmp as last resort\");\n        PathBuf::from(\"/tmp\")\n    }\n};","preventionTips":["Always set HOME (Unix) or USERPROFILE (Windows) in service/container definitions.","Set XDG_DATA_HOME explicitly on Linux to avoid the fallback path entirely.","For systemd units, add Environment=HOME= and EnvironmentFile= directives.","Test the app in a clean container to catch missing-env issues early."],"tags":["panic","env-var","home-directory","container","app-data-dir"],"backgroundTag":null,"analyzedSha":"fad3f12a147d138388a66f0d92a02b2675f65294","analyzedAt":"2026-08-12T20:33:47.516Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}