Skip to content

Commit 748f865

Browse files
committed
feat: make exception message more informative
1 parent af466f9 commit 748f865

File tree

1 file changed

+19
-1
lines changed
  • operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing

1 file changed

+19
-1
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public UpdateControl<P> execute() throws Exception {
205205
if (!exceptions.isEmpty()) {
206206
throw new AggregatedOperatorException("One or more DependentResource(s) failed:\n" +
207207
exceptions.stream()
208-
.map(e -> "\t\t- " + e.getMessage())
208+
.map(Controller.this::createExceptionInformation)
209209
.collect(Collectors.joining("\n")),
210210
exceptions);
211211
}
@@ -215,6 +215,24 @@ public UpdateControl<P> execute() throws Exception {
215215
});
216216
}
217217

218+
private String createExceptionInformation(Exception e) {
219+
final var exceptionLocation = Optional.ofNullable(e.getCause())
220+
.map(Throwable::getStackTrace)
221+
.filter(stackTrace -> stackTrace.length > 0)
222+
.map(stackTrace -> {
223+
int i = 0;
224+
while (i < stackTrace.length) {
225+
final var moduleName = stackTrace[i].getModuleName();
226+
if (!"java.base".equals(moduleName)) {
227+
return " at: " + stackTrace[i].toString();
228+
}
229+
i++;
230+
}
231+
return "";
232+
});
233+
return "\t\t- " + e.getMessage() + exceptionLocation.orElse("");
234+
}
235+
218236
public void initAndRegisterEventSources(EventSourceContext<P> context) {
219237
dependents.entrySet().stream()
220238
.filter(drEntry -> drEntry.getValue() instanceof EventSourceProvider)

0 commit comments

Comments
 (0)