bee-san/RustScan · error
Could not infer ScriptConfig path.
Error message
Could not infer ScriptConfig path.
What it means
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.)
Source
Thrown at src/scripts/mod.rs:395
None
}
}
}
}
#[derive(Debug, Deserialize, Clone)]
pub struct ScriptConfig {
pub tags: Option<Vec<String>>,
pub ports: Option<Vec<String>>,
pub developer: Option<Vec<String>>,
pub directory: Option<String>,
}
#[cfg(not(tarpaulin_include))]
impl ScriptConfig {
pub fn read_config() -> Result<ScriptConfig> {
let Some(mut home_dir) = dirs::home_dir() else {
return Err(anyhow!("Could not infer ScriptConfig path."));
};
home_dir.push(".rustscan_scripts.toml");
let content = fs::read_to_string(home_dir)?;
let config = toml::from_str::<ScriptConfig>(&content)?;
Ok(config)
}
}
#[cfg(test)]
mod tests {
use super::*;
// Function for testing only, it inserts static values into ip and open_ports
// Doesn't use impl in case it's implemented in the super module at some point
fn into_script(script_f: ScriptFile) -> Script {
Script::build(
script_f.path,View on GitHub (pinned to e9dadb4a30)
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)
Example fix
# before: systemd unit [Service] ExecStart=/usr/bin/rustscan -a target --scripts # after [Service] Environment=HOME=/root ExecStart=/usr/bin/rustscan -a target --scripts
Defensive patterns
Strategy: fallback
Validate before calling
use std::env;
fn can_locate_script_config() -> Result<(), String> {
match env::var_os("HOME") {
Some(h) if !h.is_empty() => Ok(()),
_ => Err("HOME is not set; rustscan cannot locate ~/.rustscan_scripts.toml".into()),
}
} Type guard
fn script_config_path_exists() -> bool {
dirs::home_dir()
.map(|h| h.join(".rustscan_scripts.toml").is_file())
.unwrap_or(false)
} Try / catch
match ScriptConfig::read_config() {
Ok(cfg) => use(cfg),
Err(e) if e.to_string().contains("Could not infer ScriptConfig path") => {
eprintln!("HOME is unset; export HOME or use the default ScriptConfig");
use(ScriptConfig::default());
}
Err(e) => return Err(e),
} Prevention
- 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
When it happens
Trigger: Calling read_config() when dirs::home_dir() is None — HOME unset on Unix, no user profile on Windows, service accounts without home dirs.
Common situations: 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.
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
- Could not infer scripts path.
- Could not infer config file path.
- Failed to parse execution format.
- Unknown exit status
- Exit code = {}
AI-assisted analysis of bee-san/RustScan@e9dadb4a30 (2026-09-02).
Data as JSON: /api/errors/48de7df31dd276de.
Report an issue: GitHub.