From e115cd1098d88e33ce23c29f7a965efb96c277b8 Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Wed, 29 Apr 2026 10:22:30 -0400 Subject: [PATCH] GP-6754: Throw Error instead of System.exit() --- .../app/util/headless/HeadlessAnalyzer.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessAnalyzer.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessAnalyzer.java index 090fd60d29..dd5a9aff76 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessAnalyzer.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessAnalyzer.java @@ -959,15 +959,17 @@ public class HeadlessAnalyzer { } } } + catch (JythonStubException e) { + // We want to effectively exit with an error code, but this class may be used as a + // Ghidra library method in some scenarios, so System.exit(1) is too aggressive. + // Throwing an Error allows Ghidra to exit with an uncaught exception when run from + // the command line, but allows for the possibility of a library client to handle + // the problem in a way that better suits their application. + throw new Error(e); + } catch (Exception exc) { String logErrorMsg = "REPORT SCRIPT ERROR: " + scriptName + " : " + exc.getMessage(); - if (exc instanceof JythonStubException) { - Msg.error(this, logErrorMsg); - System.exit(1); - } - else { - Msg.error(this, logErrorMsg, exc); - } + Msg.error(this, logErrorMsg, exc); } return retOption;