{"record":{"id":"65cc747ad3708071","repo":"unicity-aos/aos-ce","slug":"aos-home-userprofile-and-homedrive-homepath-are-all-unset","errorCode":null,"errorMessage":"AOS_HOME, USERPROFILE, and HOMEDRIVE/HOMEPATH are all unset","messagePattern":"AOS_HOME, USERPROFILE, and HOMEDRIVE/HOMEPATH are all unset","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"crates/unicity-aos-bootstrap/src/lib.rs","lineNumber":610,"sourceCode":"        fs::set_permissions(path, fs::Permissions::from_mode(0o600))?;\n    }\n    #[cfg(not(unix))]\n    let _ = path;\n    Ok(())\n}\n\n#[cfg(windows)]\nfn default_home<F>(get: &F) -> io::Result<OsString>\nwhere\n    F: Fn(&str) -> Option<OsString>,\n{\n    if let Some(home) = get(\"USERPROFILE\") {\n        return Ok(home);\n    }\n\n    match (get(\"HOMEDRIVE\"), get(\"HOMEPATH\")) {\n        (Some(drive), Some(path)) => Ok(PathBuf::from(drive).join(path).into_os_string()),\n        _ => Err(io::Error::new(\n            io::ErrorKind::NotFound,\n            \"AOS_HOME, USERPROFILE, and HOMEDRIVE/HOMEPATH are all unset\",\n        )),\n    }\n}\n\n#[cfg(not(windows))]\nfn default_home<F>(get: &F) -> io::Result<OsString>\nwhere\n    F: Fn(&str) -> Option<OsString>,\n{\n    get(\"HOME\")\n        .ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, \"AOS_HOME and HOME are both unset\"))\n}\n\n#[cfg(windows)]\nconst fn default_home_name() -> &'static str {\n    \"USERPROFILE\"","sourceCodeStart":592,"sourceCodeEnd":628,"githubUrl":"https://github.com/unicity-aos/aos-ce/blob/f6f22024fb1e8d122f28a1b4a9f75aee448ae839/crates/unicity-aos-bootstrap/src/lib.rs#L592-L628","documentation":"The Windows branch of default_home (crates/unicity-aos-bootstrap/src/lib.rs:600) resolves the AOS home directory from AOS_HOME first, then USERPROFILE, then HOMEDRIVE+HOMEPATH; if none are set it throws this io::Error (NotFound). The library needs a home directory to build its default state layout and cannot proceed without one.","triggerScenarios":"Calling resolve_with or default_legacy_runtime_home on Windows when AOS_HOME, USERPROFILE, and HOMEDRIVE/HOMEPATH are all absent from the process environment — e.g. running under a stripped-down service account, a scheduled task with a minimal environment, or a container where these vars were never set.","commonSituations":"Windows services and some CI runners run with USERPROFILE unset; custom process launches (CreateProcess / std::process::Command with cleared env) drop the variables; headless/containerized Windows builds.","solutions":["Set AOS_HOME explicitly to the desired state directory and retry.","Ensure USERPROFILE is present in the environment (it normally points to C:\\Users\\<user>).","If launching the process yourself, pass the parent environment or at minimum USERPROFILE instead of an empty env map.","As a last resort set both HOMEDRIVE (e.g. 'C:') and HOMEPATH (e.g. '\\Users\\me')."],"exampleFix":"// before: spawned with cleared env\nCommand::new(\"aos\").env_clear().status()\n// after\nCommand::new(\"aos\").env(\"AOS_HOME\", \"C:\\\\aos-state\").status()","handlingStrategy":"fallback","validationCode":"let home = std::env::var_os(\"AOS_HOME\")\n    .or_else(|| std::env::var_os(\"USERPROFILE\"))\n    .or_else(|| -> Option<std::ffi::OsString> {\n        Some(std::ffi::OsString::from(format!(\n            \"{}{}\",\n            std::env::var(\"HOMEDRIVE\").ok()?,\n            std::env::var(\"HOMEPATH\").ok()?)))\n    });\nif home.is_none() {\n    return Err(\"set AOS_HOME or USERPROFILE before running\".into());\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound && e.to_string().contains(\"HOMEDRIVE/HOMEPATH\") => {\n        eprintln!(\"no home directory in environment; set AOS_HOME=<dir> and retry\");\n    }\n    other => other?,\n}","preventionTips":["Set AOS_HOME explicitly in service definitions, scheduled tasks, and containers.","When spawning child processes, inherit the parent environment instead of env_clear().","For Windows services, configure the account profile or add Environment entries in the service/CI config."],"tags":["environment","windows","home-directory","rust"],"backgroundTag":"missing-env-var","analyzedSha":"f6f22024fb1e8d122f28a1b4a9f75aee448ae839","analyzedAt":"2026-09-13T03:04:44.565Z","contentChangedAt":"2026-09-13T03:04:44.565Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}