{"record":{"id":"d121637c0228133d","repo":"unicity-aos/aos-ce","slug":"variable-must-be-an-absolute-path","errorCode":null,"errorMessage":"{variable} must be an absolute path","messagePattern":"(.+?) must be an absolute path","errorType":"validation","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"crates/unicity-aos-bootstrap/src/lib.rs","lineNumber":100,"sourceCode":"    }\n\n    fn from_environment_root(root: OsString, variable: &str) -> io::Result<Self> {\n        Ok(Self::from_root(Self::validated_environment_root(\n            root, variable,\n        )?))\n    }\n\n    fn validated_environment_root(root: OsString, variable: &str) -> io::Result<PathBuf> {\n        if root.is_empty() {\n            return Err(io::Error::new(\n                io::ErrorKind::InvalidInput,\n                format!(\"{variable} must not be empty\"),\n            ));\n        }\n\n        let root = PathBuf::from(root);\n        if !root.is_absolute() {\n            return Err(io::Error::new(\n                io::ErrorKind::InvalidInput,\n                format!(\"{variable} must be an absolute path\"),\n            ));\n        }\n        validate_path_entry(&root, variable)?;\n        Ok(root)\n    }\n\n    /// Build an AOS home from an explicit root, useful for embedding and tests.\n    #[must_use]\n    pub fn from_root(root: impl Into<PathBuf>) -> Self {\n        Self { root: root.into() }\n    }\n\n    /// The product-owned AOS root.\n    #[must_use]\n    pub fn root(&self) -> &Path {\n        &self.root","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/unicity-aos/aos-ce/blob/f6f22024fb1e8d122f28a1b4a9f75aee448ae839/crates/unicity-aos-bootstrap/src/lib.rs#L82-L118","documentation":"validated_environment_root requires the root path to be absolute; a relative PathBuf triggers an InvalidInput io error \"{variable} must be an absolute path\", after which validate_path_entry performs further checks. Absolute paths are mandatory so runtime layout and private-directory creation cannot depend on the process's current working directory.","triggerScenarios":"Setting a root environment variable to a relative path like \"runtime\" or \"./data\" and passing it through validated_environment_root.","commonSituations":"Writing VAR=data in a shell script assuming the daemon's cwd; copying an example config that used a relative path; launching the process from an unexpected working directory so a previously-working relative value now resolves elsewhere.","solutions":["Prefix the value with \"/\" (or a drive root) in the environment: use an absolute path like /opt/myapp/runtime.","Canonicalize in the launcher script, e.g. export MYAPP_ROOT=\"$(pwd)/data\".","Reject relative values at config-load time with a clear message before the process starts."],"exampleFix":"// before\nexport MYAPP_ROOT=data/runtime\n// after\nexport MYAPP_ROOT=/var/lib/myapp/runtime","handlingStrategy":"validation","validationCode":"fn require_absolute_env_path(name: &str) -> Result<PathBuf, String> {\n    let v = std::env::var_os(name).ok_or_else(|| format!(\"{name} not set\"))?;\n    let p = PathBuf::from(&v);\n    if p.as_os_str().is_empty() { return Err(format!(\"{name} is empty\")); }\n    if !p.is_absolute() { return Err(format!(\"{name} must be absolute, got {:?}\", p)); }\n    Ok(p)\n}","typeGuard":"fn is_absolute_path(v: &OsStr) -> bool {\n    !v.is_empty() && Path::new(v).is_absolute()\n}","tryCatchPattern":"match validated_environment_root(root, \"MYAPP_ROOT\") {\n    Err(e) if e.to_string().contains(\"must be an absolute path\") => {\n        eprintln!(\"fix MYAPP_ROOT in the unit file/script to start with /\");\n    }\n    other => other?,\n}","preventionTips":["Always write absolute paths into environment-based configuration, even in examples.","In launch scripts derive absolute values: export MYAPP_ROOT=\"$(realpath data)\".","Lint deployment configs (systemd units, Dockerfiles) for relative path values in env assignments."],"tags":["env-var","path","validation","rust"],"backgroundTag":"invalid-env-var-value","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"}