From 662b478a4877ac39b1d8860a1ce4ebeab4034a92 Mon Sep 17 00:00:00 2001 From: fermosan <78906279+fermosan@users.noreply.github.com> Date: Sun, 25 Oct 2026 20:12:30 +0200 Subject: [PATCH] Fix exception-masking bugs in Script.java and DefaultModuleDefinitionSet Two unrelated-looking bugs share the same root defect: code that catches an exception, then re-logs or re-throws it in a way that discards the actual error detail. - Script.executeInternal(): the non-zero-exit failure path opened a new BufferedReader on a stream a draining Task had already consumed and closed, so interpreter.processError() always threw "Stream closed" instead of surfacing the real process output. Fixed by reusing task.getResult() when interpreter.drain() is true, mirroring the success path's existing logic. Two occurrences in the same file. - DefaultModuleDefinitionSet.loadContext(): the caught exception was passed as an ordinary format-string argument to logger.error() instead of SLF4J's trailing-throwable argument, so the stack trace was never logged. The re-thrown RuntimeException also didn't chain the original cause. Fixed both: pass the exception as the throwable arg, and set it as the new exception's cause. Both were found while diagnosing real failures where the underlying error was invisible in the logs and had to be recovered by manually patching these exact lines. --- .../spring/module/model/impl/DefaultModuleDefinitionSet.java | 4 ++-- utils/src/main/java/com/cloud/utils/script/Script.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java index 78693f72140c..5f829498bff7 100644 --- a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java @@ -145,8 +145,8 @@ public void with(ModuleDefinition def, Stack parents) { logger.debug("Failed to obtain module context: ", e); } } catch (BeansException e) { - logger.error("Failed to load module [{}] due to: {}", def.getName(), e); - throw new RuntimeException(String.format("Failed to load module [%s]", def.getName())); + logger.error("Failed to load module [{}]", def.getName(), e); + throw new RuntimeException(String.format("Failed to load module [%s]", def.getName()), e); } } }); diff --git a/utils/src/main/java/com/cloud/utils/script/Script.java b/utils/src/main/java/com/cloud/utils/script/Script.java index 5a92d12eeda9..96d1f9ffe144 100644 --- a/utils/src/main/java/com/cloud/utils/script/Script.java +++ b/utils/src/main/java/com/cloud/utils/script/Script.java @@ -371,7 +371,7 @@ private String executeInternal(OutputInterpreter interpreter, Map