{"record":{"id":"246b1d5dc9b02399","repo":"bee-san/RustScan","slug":"exit-code","errorCode":null,"errorMessage":"Exit code = {}","messagePattern":"Exit code = (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/scripts/mod.rs","lineNumber":312,"sourceCode":"            let status = output.status;\n\n            let es = match status.code() {\n                Some(code) => code,\n                _ => {\n                    #[cfg(unix)]\n                    {\n                        status.signal().unwrap()\n                    }\n\n                    #[cfg(windows)]\n                    {\n                        return Err(anyhow!(\"Unknown exit status\"));\n                    }\n                }\n            };\n\n            if es != 0 {\n                return Err(anyhow!(\"Exit code = {}\", es));\n            }\n            Ok(String::from_utf8_lossy(&output.stdout).into_owned())\n        }\n        Err(error) => {\n            debug!(\"Command error {error}\",);\n            Err(anyhow!(error.to_string()))\n        }\n    }\n}\n\npub fn find_scripts(path: PathBuf) -> Result<Vec<PathBuf>> {\n    if path.is_dir() {\n        debug!(\"Scripts folder found {}\", &path.display());\n        let mut files_vec: Vec<PathBuf> = Vec::new();\n        for entry in fs::read_dir(path)? {\n            let entry = entry?;\n            files_vec.push(entry.path());\n        }","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/bee-san/RustScan/blob/e9dadb4a30dd0f3cc8b9b1c630a28ad351f8dbc3/src/scripts/mod.rs#L294-L330","documentation":"After a script process finishes, execute_script inspects its exit code; any non-zero code becomes the anyhow error 'Exit code = {code}'. This is not a rustscan bug — the script itself ran and failed, and rustscan surfaces the script's own exit status to the caller.","triggerScenarios":"Any executed script (bash/python/perl/custom call_format) returns a non-zero exit status — e.g. a script exits 1 on a failed scan or an unhandled interpreter error.","commonSituations":"Scripts with syntax errors or missing interpreter modules; nmap-style helper scripts exiting non-zero when a target is unreachable; scripts that use non-zero codes to signal 'no results', which rustscan treats as failure.","solutions":["Run the script standalone to reproduce and fix the failing logic inside the script","Check the script's stderr/debug logs (rustscan debug flag) for the interpreter's error message","Ensure the script exits 0 on success paths (avoid using non-zero for soft outcomes)","Verify the interpreter and dependencies the script needs are installed in the environment"],"exampleFix":"// before: scan.sh\nnmap -p $1 $2   # exits non-zero if host down\n// after\nnmap -p $1 $2 || true","handlingStrategy":"try-catch","validationCode":"// Smoke-test the script standalone before using it in rustscan\nfn script_smoke_ok(call_format: &str) -> bool {\n    std::process::Command::new(\"sh\").arg(\"-c\").arg(call_format)\n        .output().map(|o| o.status.success()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match script.run() {\n    Ok(out) => println!(\"{out}\"),\n    Err(e) if e.to_string().starts_with(\"Exit code = \") => {\n        let code = e.to_string().trim_start_matches(\"Exit code = \");\n        eprintln!(\"Script itself failed with code {code}; inspect script stderr/debug logs\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Exit 0 on success paths in your scripts; reserve non-zero for real failures","Test each script manually with representative arguments before wiring into rustscan","Check interpreter/dependency availability in the target environment","Enable rustscan debug logging to capture the script's own stderr"],"tags":["rust","scripts","exit-code","process"],"backgroundTag":"nonzero-exit-code","analyzedSha":"e9dadb4a30dd0f3cc8b9b1c630a28ad351f8dbc3","analyzedAt":"2026-09-02T04:27:33.555Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}