This is an automated email from the ASF dual-hosted git repository.
RosiKyu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/main by this push:
new 8ee3da51518 Fix exception-masking bugs in Script.java and
DefaultModuleDefinitionSet (#14498)
8ee3da51518 is described below
commit 8ee3da515181686c773289c7cb15073ff9939cd6
Author: fermosan <[email protected]>
AuthorDate: Tue Nov 17 17:25:19 2026 +0200
Fix exception-masking bugs in Script.java and DefaultModuleDefinitionSet
(#14498)
* 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.
* Addition of a helper method
---
.../module/model/impl/DefaultModuleDefinitionSet.java | 4 ++--
utils/src/main/java/com/cloud/utils/script/Script.java | 18 ++++++++++++++++--
2 files changed, 18 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 add33b349aa..ac7a0bf90c5 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
@@ -149,8 +149,8 @@ public class DefaultModuleDefinitionSet implements
ModuleDefinitionSet {
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 5a92d12eeda..01699269bec 100644
--- a/utils/src/main/java/com/cloud/utils/script/Script.java
+++ b/utils/src/main/java/com/cloud/utils/script/Script.java
@@ -244,6 +244,20 @@ public class Script implements Callable<String> {
}
}
+ /**
+ * Builds the error result of a failed process whose output was drained by
the interpreter task.
+ * Draining interpreters (e.g. {@link OutputInterpreter.AllLinesParser})
return null from interpret(),
+ * and callers treat a null result as success, so a non-null value must
always be returned here:
+ * the task result, otherwise the output captured by the parser, otherwise
the process exit value.
+ */
+ private String getDrainedErrorResult(Task task, OutputInterpreter
interpreter) throws InterruptedException {
+ String result = task.getResult();
+ if (StringUtils.isBlank(result) && interpreter instanceof
OutputInterpreter.AllLinesParser) {
+ result = ((OutputInterpreter.AllLinesParser)
interpreter).getLines();
+ }
+ return StringUtils.isNotBlank(result) ? result.trim() :
String.valueOf(_process.exitValue());
+ }
+
public String execute(OutputInterpreter interpreter) {
return executeInternal(interpreter, null);
}
@@ -371,7 +385,7 @@ public class Script implements Callable<String> {
String error;
if (interpreter != null) {
- error = interpreter.processError(reader);
+ error = interpreter.drain() ? getDrainedErrorResult(task,
interpreter) : interpreter.processError(reader);
} else {
error = String.valueOf(_process.exitValue());
}
@@ -494,7 +508,7 @@ public class Script implements Callable<String> {
String error;
if (interpreter != null) {
- error = interpreter.processError(reader);
+ error = interpreter.drain() ? getDrainedErrorResult(task,
interpreter) : interpreter.processError(reader);
} else {
error = String.valueOf(_process.exitValue());
}