{"record":{"id":"fa844603e15200a6","repo":"unicity-aos/aos-ce","slug":"variable-must-not-be-empty","errorCode":null,"errorMessage":"{variable} must not be empty","messagePattern":"(.+?) must not be empty","errorType":"validation","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"crates/unicity-aos-bootstrap/src/lib.rs","lineNumber":92,"sourceCode":"    {\n        if let Some(root) = get(\"AOS_HOME\") {\n            return Self::from_environment_root(root, \"AOS_HOME\");\n        }\n\n        let home = default_home(&get)?;\n        let home = Self::validated_environment_root(home, default_home_name())?;\n        Ok(Self::from_root(home.join(\".aos\")))\n    }\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]","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/unicity-aos/aos-ce/blob/f6f22024fb1e8d122f28a1b4a9f75aee448ae839/crates/unicity-aos-bootstrap/src/lib.rs#L74-L110","documentation":"validated_environment_root rejects an empty OsString root with an InvalidInput io error formatted as \"{variable} must not be empty\", where {variable} is the environment variable name being read. It is the first of several validations applied to root-directory environment variables before the value is turned into a PathBuf.","triggerScenarios":"Reading a root-directory environment variable whose value is set but empty (e.g. export FOO_ROOT=) and passing it to validated_environment_root via the wrapper that formats the error with the variable name.","commonSituations":"An unset variable expanded to empty string in a shell script; a CI secret defined but left blank; a systemd unit or Dockerfile ENV that sets the variable to \"\"; a profile file exporting VAR= with no value.","solutions":["Set the environment variable to a non-empty absolute path before launching the process.","Provide a sensible default in code when the variable is empty or missing.","Fail fast at startup with a clear message naming the variable so operators fix the environment, not the code."],"exampleFix":"// before\nlet root = std::env::var_os(\"MYAPP_ROOT\").unwrap_or_default();\nlet root = validated_environment_root(root, \"MYAPP_ROOT\")?;\n// after\nlet root = match std::env::var_os(\"MYAPP_ROOT\") {\n    Some(v) if !v.is_empty() => v,\n    _ => return Err(\"MYAPP_ROOT must be set to an absolute path\".into()),\n};\nlet root = validated_environment_root(root, \"MYAPP_ROOT\")?;","handlingStrategy":"validation","validationCode":"fn require_non_empty_env(name: &str) -> Result<OsString, String> {\n    match std::env::var_os(name) {\n        Some(v) if !v.is_empty() => Ok(v),\n        Some(_) => Err(format!(\"{name} is set but empty\")),\n        None => Err(format!(\"{name} is not set\")),\n    }\n}","typeGuard":null,"tryCatchPattern":"match validated_environment_root(root, \"MYAPP_ROOT\") {\n    Err(e) if e.kind() == io::ErrorKind::InvalidInput && e.to_string().contains(\"must not be empty\") => {\n        eprintln!(\"MYAPP_ROOT is empty; set it to an absolute path\");\n    }\n    other => other?,\n}","preventionTips":["In shell launchers use ${VAR:?msg} to abort on unset/empty variables before exec.","Validate all required environment variables once at process startup with a single check function.","In CI, mark required secret/variable fields as mandatory so they cannot be saved blank."],"tags":["env-var","validation","rust","config"],"backgroundTag":"empty-required-field","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"}