bee-san/RustScan · error

Could not infer scripts path.

Error message

Could not infer scripts path.

What it means

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.

Source

Thrown at src/scripts/mod.rs:117

#[cfg(not(tarpaulin_include))]
pub fn init_scripts(scripts: &ScriptsRequired) -> Result<Vec<ScriptFile>> {
    let mut scripts_to_run: Vec<ScriptFile> = Vec::new();

    match scripts {
        ScriptsRequired::None => {}
        ScriptsRequired::Default => {
            let default_script =
                toml::from_str::<ScriptFile>(DEFAULT).expect("Failed to parse Script file.");
            scripts_to_run.push(default_script);
        }
        ScriptsRequired::Custom => {
            let script_config = ScriptConfig::read_config()?;
            debug!("Script config \n{script_config:?}");

            let script_dir_base = if let Some(config_directory) = &script_config.directory {
                PathBuf::from(config_directory)
            } else {
                dirs::home_dir().ok_or_else(|| anyhow!("Could not infer scripts path."))?
            };

            let script_paths = find_scripts(script_dir_base)?;
            debug!("Scripts paths \n{script_paths:?}");

            let parsed_scripts = parse_scripts(script_paths);
            debug!("Scripts parsed \n{parsed_scripts:?}");

            // Only Scripts that contain all the tags found in ScriptConfig will be selected.
            if let Some(config_hashset) = script_config.tags {
                for script in parsed_scripts {
                    if let Some(script_hashset) = &script.tags {
                        if script_hashset
                            .iter()
                            .all(|tag| config_hashset.contains(tag))
                        {
                            scripts_to_run.push(script);
                        } else {

View on GitHub (pinned to e9dadb4a30)

Solutions

  1. Set HOME before running (export HOME=/home/user)
  2. Add a 'directory = "/path/to/scripts"' entry to ~/.rustscan_scripts.toml (or the config-dir variant) so home_dir is not consulted
  3. Run as a user whose home directory exists in /etc/passwd
  4. Alternatively set the scripts directory in the main rustscan config if supported

Example fix

// before: ~/.rustscan_scripts.toml
[tag]
ports = [80]
// after
[tag]
ports = [80]

directory = "/opt/rustscan-scripts"
Defensive patterns

Strategy: fallback

Validate before calling

use std::env;
use std::path::PathBuf;

fn resolve_script_base(cfg_dir: Option<&str>) -> Result<PathBuf, String> {
    if let Some(d) = cfg_dir {
        return Ok(PathBuf::from(d));
    }
    env::var_os("HOME")
        .map(PathBuf::from)
        .ok_or_else(|| "HOME is unset and no script directory is configured".into())
}

Type guard

fn scripts_path_resolvable(configured: Option<&str>) -> bool {
    configured.map(|d| std::path::Path::new(d).is_dir()).unwrap_or(false)
        || dirs::home_dir().is_some()
}

Try / catch

match init_scripts() {
    Ok(scripts) => run(scripts),
    Err(e) if e.to_string().contains("Could not infer scripts path") => {
        eprintln!("Set HOME or add 'directory' to ~/.rustscan_scripts.toml");
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of bee-san/RustScan@e9dadb4a30 (2026-09-02). Data as JSON: /api/errors/099c445fbc32116e. Report an issue: GitHub.