{"record":{"id":"48de7df31dd276de","repo":"bee-san/RustScan","slug":"could-not-infer-scriptconfig-path","errorCode":null,"errorMessage":"Could not infer ScriptConfig path.","messagePattern":"Could not infer ScriptConfig path\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/scripts/mod.rs","lineNumber":395,"sourceCode":"                None\n            }\n        }\n    }\n}\n\n#[derive(Debug, Deserialize, Clone)]\npub struct ScriptConfig {\n    pub tags: Option<Vec<String>>,\n    pub ports: Option<Vec<String>>,\n    pub developer: Option<Vec<String>>,\n    pub directory: Option<String>,\n}\n\n#[cfg(not(tarpaulin_include))]\nimpl ScriptConfig {\n    pub fn read_config() -> Result<ScriptConfig> {\n        let Some(mut home_dir) = dirs::home_dir() else {\n            return Err(anyhow!(\"Could not infer ScriptConfig path.\"));\n        };\n        home_dir.push(\".rustscan_scripts.toml\");\n\n        let content = fs::read_to_string(home_dir)?;\n        let config = toml::from_str::<ScriptConfig>(&content)?;\n        Ok(config)\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    // Function for testing only, it inserts static values into ip and open_ports\n    // Doesn't use impl in case it's implemented in the super module at some point\n    fn into_script(script_f: ScriptFile) -> Script {\n        Script::build(\n            script_f.path,","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/bee-san/RustScan/blob/e9dadb4a30dd0f3cc8b9b1c630a28ad351f8dbc3/src/scripts/mod.rs#L377-L413","documentation":"ScriptConfig::read_config loads ~/.rustscan_scripts.toml. If the OS cannot determine a home directory, it returns the anyhow error 'Could not infer ScriptConfig path.' before even attempting to read the file. (A missing or malformed file produces different errors.)","triggerScenarios":"Calling read_config() when dirs::home_dir() is None — HOME unset on Unix, no user profile on Windows, service accounts without home dirs.","commonSituations":"Docker/CI containers running rustscan without HOME; systemd units with a sanitized environment; cron jobs with a minimal PATH/env; running as 'nobody' or a metasploit/service user with no home directory.","solutions":["Set HOME before invoking rustscan (export HOME=/home/user)","Run under a user account that has a home directory defined in /etc/passwd","In systemd, add Environment=HOME=%h or set it in the unit's [Service] section","Ensure the Docker image defines ENV HOME (e.g. ENV HOME=/root)"],"exampleFix":"# before: systemd unit\n[Service]\nExecStart=/usr/bin/rustscan -a target --scripts\n# after\n[Service]\nEnvironment=HOME=/root\nExecStart=/usr/bin/rustscan -a target --scripts","handlingStrategy":"fallback","validationCode":"use std::env;\n\nfn can_locate_script_config() -> Result<(), String> {\n    match env::var_os(\"HOME\") {\n        Some(h) if !h.is_empty() => Ok(()),\n        _ => Err(\"HOME is not set; rustscan cannot locate ~/.rustscan_scripts.toml\".into()),\n    }\n}","typeGuard":"fn script_config_path_exists() -> bool {\n    dirs::home_dir()\n        .map(|h| h.join(\".rustscan_scripts.toml\").is_file())\n        .unwrap_or(false)\n}","tryCatchPattern":"match ScriptConfig::read_config() {\n    Ok(cfg) => use(cfg),\n    Err(e) if e.to_string().contains(\"Could not infer ScriptConfig path\") => {\n        eprintln!(\"HOME is unset; export HOME or use the default ScriptConfig\");\n        use(ScriptConfig::default());\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Export HOME in Docker, CI, cron, and systemd environments (Environment=HOME=...)","Run rustscan as a user with a real home directory","Confirm the user's passwd entry has a valid home path (getent passwd $(whoami))","Fall back to ScriptConfig defaults when the file cannot be located"],"tags":["rust","config","environment","scripts"],"backgroundTag":"missing-env-var","analyzedSha":"e9dadb4a30dd0f3cc8b9b1c630a28ad351f8dbc3","analyzedAt":"2026-09-02T04:27:33.555Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}