{"record":{"id":"1b484a24b062b387","repo":"bee-san/RustScan","slug":"could-not-infer-config-file-path","errorCode":null,"errorMessage":"Could not infer config file path.","messagePattern":"Could not infer config file path\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/input.rs","lineNumber":327,"sourceCode":"            }\n        }\n\n        let config: Config = match toml::from_str(&content) {\n            Ok(config) => config,\n            Err(e) => {\n                println!(\"Found {e} in configuration file.\\nAborting scan.\\n\");\n                std::process::exit(1);\n            }\n        };\n\n        config\n    }\n}\n\n/// Constructs default path to config toml\npub fn default_config_path() -> PathBuf {\n    let Some(mut config_path) = dirs::config_dir() else {\n        panic!(\"Could not infer config file path.\");\n    };\n    config_path.push(\".rustscan.toml\");\n    config_path\n}\n\n/// Returns the deprecated home directory config path used for backwards compatibility.\npub fn old_default_config_path() -> PathBuf {\n    let Some(mut config_path) = dirs::home_dir() else {\n        panic!(\"Could not infer config file path.\");\n    };\n    config_path.push(\".rustscan.toml\");\n    config_path\n}\n\n#[cfg(test)]\nmod tests {\n    use clap::{CommandFactory, Parser};\n    use parameterized::parameterized;","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/bee-san/RustScan/blob/e9dadb4a30dd0f3cc8b9b1c630a28ad351f8dbc3/src/input.rs#L309-L345","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set the HOME environment variable to the user's home directory before running (export HOME=/root or /home/<user>)","On Linux, also set XDG_CONFIG_HOME (e.g. export XDG_CONFIG_HOME=$HOME/.config) so config_dir() resolves","Run the tool as a normal user account that has a home directory","As a workaround, pass config explicitly via --config if available instead of relying on the default path"],"exampleFix":"// before (shell)\nrustscan -a 127.0.0.1   # HOME unset in Docker -> panic\n// after\nexport HOME=/root\nrustscan -a 127.0.0.1","handlingStrategy":"fallback","validationCode":"use std::env;\nuse std::path::PathBuf;\n\nfn ensure_config_env() -> Result<(), String> {\n    if env::var_os(\"HOME\").is_none() && env::var_os(\"XDG_CONFIG_HOME\").is_none() {\n        return Err(\"Neither HOME nor XDG_CONFIG_HOME is set; rustscan cannot infer its config path.\".into());\n    }\n    Ok(())\n}","typeGuard":"fn has_config_dir() -> bool {\n    dirs::config_dir().map(|p| p.is_dir()).unwrap_or(false)\n}","tryCatchPattern":"match std::panic::catch_unwind(input::default_config_path) {\n    Ok(path) => use_path(path),\n    Err(_) => eprintln!(\"Set HOME/XDG_CONFIG_HOME so rustscan can find .rustscan.toml\"),\n}\n// or in Rust 2021+ with the panic hook scoped:\nlet prev = std::panic::take_hook();\nstd::panic::set_hook(Box::new(|_| {}));\nlet r = std::panic::catch_unwind(input::default_config_path);\nstd::panic::set_hook(prev);","preventionTips":["Always export HOME (and XDG_CONFIG_HOME on Linux) in Docker images and CI before running rustscan","Check `echo $HOME` is non-empty in the shell where rustscan runs","Run rustscan as a normal user, not a no-home service account","Use explicit --config <path> where supported instead of relying on the default location"],"tags":["rust","config","environment","panic"],"backgroundTag":"missing-env-var","analyzedSha":"e9dadb4a30dd0f3cc8b9b1c630a28ad351f8dbc3","analyzedAt":"2026-09-02T04:27:33.555Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}