From 4d9ffdd8315a5a5da1fbab14ba5deed1cbe9f700 Mon Sep 17 00:00:00 2001 From: Tim Quinn Date: Tue, 7 Jan 2025 16:18:40 -0600 Subject: [PATCH] Further improve rendering error reporting --- .../maven/sitegen/RenderingException.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/maven-plugins/sitegen-maven-plugin/src/main/java/io/helidon/build/maven/sitegen/RenderingException.java b/maven-plugins/sitegen-maven-plugin/src/main/java/io/helidon/build/maven/sitegen/RenderingException.java index a00e8218d..f76deed41 100644 --- a/maven-plugins/sitegen-maven-plugin/src/main/java/io/helidon/build/maven/sitegen/RenderingException.java +++ b/maven-plugins/sitegen-maven-plugin/src/main/java/io/helidon/build/maven/sitegen/RenderingException.java @@ -16,12 +16,11 @@ package io.helidon.build.maven.sitegen; -import java.io.PrintWriter; -import java.io.StringWriter; import java.util.ArrayDeque; import java.util.Arrays; import java.util.Deque; import java.util.List; +import java.util.StringJoiner; import java.util.stream.Collectors; import freemarker.template.TemplateException; @@ -50,12 +49,20 @@ public RenderingException(List errors) { } private static String allErrorInfo(List errors) { - StringWriter sw = new StringWriter(); - try (PrintWriter pw = new PrintWriter(sw)) { - errors.forEach(t -> t.printStackTrace(pw)); - return sw.toString(); + return errors.stream() + .map(RenderingException::cascadeMessages) + .collect(Collectors.joining()); + } + + private static String cascadeMessages(Throwable error){ + StringJoiner result = new StringJoiner(System.lineSeparator()); + while (error != null) { + result.add(error.getMessage()); + error = error.getCause(); } + return result.toString(); } + /** * Create a new instance. *