{"record":{"id":"d881bf0eeb9205ca","repo":"t8y2/dbx","slug":"raise-systemexit-main","errorCode":null,"errorMessage":"raise SystemExit(main())","messagePattern":"raise SystemExit\\(main\\(\\)\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"agents/scripts/validate_windows_pe_dependencies.py","lineNumber":130,"sourceCode":"    parser = argparse.ArgumentParser(description=\"Reject Windows PE files that require the Visual C++ runtime\")\n    parser.add_argument(\"binary\", type=Path)\n    args = parser.parse_args()\n\n    try:\n        imports = imported_dlls(args.binary)\n    except (OSError, PeFormatError) as error:\n        parser.error(str(error))\n\n    forbidden = forbidden_msvc_runtime_dlls(imports)\n    if forbidden:\n        parser.error(f\"dynamic Visual C++ runtime dependencies found: {', '.join(forbidden)}\")\n\n    print(f\"Validated {args.binary}: {len(imports)} imported DLLs, no dynamic Visual C++ runtime\")\n    return 0\n\n\nif __name__ == \"__main__\":\n    raise SystemExit(main())\n","sourceCodeStart":112,"sourceCodeEnd":131,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/scripts/validate_windows_pe_dependencies.py#L112-L131","documentation":"This is not a thrown error but the standard Python idiom at the bottom of a CLI script: main() is executed and its integer return value is passed to SystemExit as the process exit code. Returning 0 means validation succeeded (all imported DLLs checked, no dynamic Visual C++ runtime found); any nonzero return or uncaught exception exits non-zero. It exists so CI and shell wrappers can detect validation failure programmatically.","triggerScenarios":"Running `python agents/scripts/validate_windows_pe_dependencies.py <binary>` from the command line or CI; the interpreter reaches the `if __name__ == \"__main__\"` block, calls main(), and raises SystemExit with the returned status code.","commonSituations":"CI pipelines validating that a built Windows PE binary does not dynamically link the Visual C++ runtime; developers running the validator locally before shipping a release binary.","solutions":["No fix needed when the exit code is 0 — validation passed","If the exit code is nonzero, re-run the script with stderr visible to see which validation step failed (missing binary, unexpected VC++ import)","Ensure the script is executed as the main module (`python script.py`), not imported, so this block runs"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import subprocess\nr = subprocess.run([\"python\", \"agents/scripts/validate_windows_pe_dependencies.py\", binary], capture_output=True)\nif r.returncode != 0:\n    raise RuntimeError(r.stderr.decode())","typeGuard":null,"tryCatchPattern":"try:\n    validate_pe(binary)\nexcept SystemExit as e:\n    if e.code != 0: handle_failure(e.code)","preventionTips":["Check the exit code, not stdout, when invoking the validator in CI","Run with stderr visible so the failing validation step is diagnosable"],"tags":["python","cli","exit-code","packaging"],"backgroundTag":"nonzero-exit-code","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}