bee-san/RustScan · error

Could not infer config file path.

Error message

Could not infer config file path.

What it means

RustScan calls dirs::config_dir() to locate the user's platform configuration directory (e.g. ~/.config on Linux, ~/Library/Application Support on macOS, %APPDATA% on Windows). If the OS environment provides no such directory, default_config_path panics with 'Could not infer config file path.' because it cannot construct a default location for .rustscan.toml.

Source

Thrown at src/input.rs:327

            }
        }

        let config: Config = match toml::from_str(&content) {
            Ok(config) => config,
            Err(e) => {
                println!("Found {e} in configuration file.\nAborting scan.\n");
                std::process::exit(1);
            }
        };

        config
    }
}

/// Constructs default path to config toml
pub fn default_config_path() -> PathBuf {
    let Some(mut config_path) = dirs::config_dir() else {
        panic!("Could not infer config file path.");
    };
    config_path.push(".rustscan.toml");
    config_path
}

/// Returns the deprecated home directory config path used for backwards compatibility.
pub fn old_default_config_path() -> PathBuf {
    let Some(mut config_path) = dirs::home_dir() else {
        panic!("Could not infer config file path.");
    };
    config_path.push(".rustscan.toml");
    config_path
}

#[cfg(test)]
mod tests {
    use clap::{CommandFactory, Parser};
    use parameterized::parameterized;

View on GitHub (pinned to e9dadb4a30)

Solutions

  1. Set the HOME environment variable to the user's home directory before running (export HOME=/root or /home/<user>)
  2. On Linux, also set XDG_CONFIG_HOME (e.g. export XDG_CONFIG_HOME=$HOME/.config) so config_dir() resolves
  3. Run the tool as a normal user account that has a home directory
  4. As a workaround, pass config explicitly via --config if available instead of relying on the default path

Example fix

// before (shell)
rustscan -a 127.0.0.1   # HOME unset in Docker -> panic
// after
export HOME=/root
rustscan -a 127.0.0.1
Defensive patterns

Strategy: fallback

Validate before calling

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

fn ensure_config_env() -> Result<(), String> {
    if env::var_os("HOME").is_none() && env::var_os("XDG_CONFIG_HOME").is_none() {
        return Err("Neither HOME nor XDG_CONFIG_HOME is set; rustscan cannot infer its config path.".into());
    }
    Ok(())
}

Type guard

fn has_config_dir() -> bool {
    dirs::config_dir().map(|p| p.is_dir()).unwrap_or(false)
}

Try / catch

match std::panic::catch_unwind(input::default_config_path) {
    Ok(path) => use_path(path),
    Err(_) => eprintln!("Set HOME/XDG_CONFIG_HOME so rustscan can find .rustscan.toml"),
}
// or in Rust 2021+ with the panic hook scoped:
let prev = std::panic::take_hook();
std::panic::set_hook(Box::new(|_| {}));
let r = std::panic::catch_unwind(input::default_config_path);
std::panic::set_hook(prev);

Prevention

When it happens

Trigger: Calling default_config_path() (directly or via read) on a system where dirs::config_dir() returns None — typically when XDG_CONFIG_HOME and HOME are both unset on Linux, or the user profile/APPDATA is missing on Windows.

Common situations: Running rustscan in minimal Docker containers or stripped CI images without HOME set; systemd services with sanitized environments; running as a user with no home directory (nobody, service accounts); cron jobs with a minimal env.

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/1b484a24b062b387. Report an issue: GitHub.