{"record":{"id":"099c445fbc32116e","repo":"bee-san/RustScan","slug":"could-not-infer-scripts-path","errorCode":null,"errorMessage":"Could not infer scripts path.","messagePattern":"Could not infer scripts path\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/scripts/mod.rs","lineNumber":117,"sourceCode":"#[cfg(not(tarpaulin_include))]\npub fn init_scripts(scripts: &ScriptsRequired) -> Result<Vec<ScriptFile>> {\n    let mut scripts_to_run: Vec<ScriptFile> = Vec::new();\n\n    match scripts {\n        ScriptsRequired::None => {}\n        ScriptsRequired::Default => {\n            let default_script =\n                toml::from_str::<ScriptFile>(DEFAULT).expect(\"Failed to parse Script file.\");\n            scripts_to_run.push(default_script);\n        }\n        ScriptsRequired::Custom => {\n            let script_config = ScriptConfig::read_config()?;\n            debug!(\"Script config \\n{script_config:?}\");\n\n            let script_dir_base = if let Some(config_directory) = &script_config.directory {\n                PathBuf::from(config_directory)\n            } else {\n                dirs::home_dir().ok_or_else(|| anyhow!(\"Could not infer scripts path.\"))?\n            };\n\n            let script_paths = find_scripts(script_dir_base)?;\n            debug!(\"Scripts paths \\n{script_paths:?}\");\n\n            let parsed_scripts = parse_scripts(script_paths);\n            debug!(\"Scripts parsed \\n{parsed_scripts:?}\");\n\n            // Only Scripts that contain all the tags found in ScriptConfig will be selected.\n            if let Some(config_hashset) = script_config.tags {\n                for script in parsed_scripts {\n                    if let Some(script_hashset) = &script.tags {\n                        if script_hashset\n                            .iter()\n                            .all(|tag| config_hashset.contains(tag))\n                        {\n                            scripts_to_run.push(script);\n                        } else {","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/bee-san/RustScan/blob/e9dadb4a30dd0f3cc8b9b1c630a28ad351f8dbc3/src/scripts/mod.rs#L99-L135","documentation":"init_scripts resolves the base directory for script files: the configured directory from ScriptConfig, or otherwise the user's home directory. If no directory is configured and dirs::home_dir() returns None, it returns the anyhow error 'Could not infer scripts path.' and main aborts.","triggerScenarios":"Running rustscan with script execution enabled when .rustscan_scripts.toml has no 'directory' key AND the environment has no resolvable home directory (HOME unset on Unix, no profile on Windows).","commonSituations":"Docker/CI images without HOME where users expect script scanning to work; running under systemd with Environment=HOME not set; broken passwd entries for the current user.","solutions":["Set HOME before running (export HOME=/home/user)","Add a 'directory = \"/path/to/scripts\"' entry to ~/.rustscan_scripts.toml (or the config-dir variant) so home_dir is not consulted","Run as a user whose home directory exists in /etc/passwd","Alternatively set the scripts directory in the main rustscan config if supported"],"exampleFix":"// before: ~/.rustscan_scripts.toml\n[tag]\nports = [80]\n// after\n[tag]\nports = [80]\n\ndirectory = \"/opt/rustscan-scripts\"","handlingStrategy":"fallback","validationCode":"use std::env;\nuse std::path::PathBuf;\n\nfn resolve_script_base(cfg_dir: Option<&str>) -> Result<PathBuf, String> {\n    if let Some(d) = cfg_dir {\n        return Ok(PathBuf::from(d));\n    }\n    env::var_os(\"HOME\")\n        .map(PathBuf::from)\n        .ok_or_else(|| \"HOME is unset and no script directory is configured\".into())\n}","typeGuard":"fn scripts_path_resolvable(configured: Option<&str>) -> bool {\n    configured.map(|d| std::path::Path::new(d).is_dir()).unwrap_or(false)\n        || dirs::home_dir().is_some()\n}","tryCatchPattern":"match init_scripts() {\n    Ok(scripts) => run(scripts),\n    Err(e) if e.to_string().contains(\"Could not infer scripts path\") => {\n        eprintln!(\"Set HOME or add 'directory' to ~/.rustscan_scripts.toml\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always set an explicit 'directory' in ~/.rustscan_scripts.toml so home_dir is never consulted","Export HOME in Docker, CI, cron, and systemd environments","Create the scripts directory ahead of time","Verify with a dry run that script discovery works in the target environment"],"tags":["rust","scripts","environment","config"],"backgroundTag":"missing-env-var","analyzedSha":"e9dadb4a30dd0f3cc8b9b1c630a28ad351f8dbc3","analyzedAt":"2026-09-02T04:27:33.555Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}