Skip to content

Commit da616dd

Browse files
committed
gradle-extensions-plugin: fix output of exceptions with multiple nested suppressed exceptions
1 parent 9fa7b39 commit da616dd

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ Change log
191191
----------
192192
v1.72
193193
* jandex-plugin: add `maxErrors` option to show several errors rather than stop on the first one
194+
* gradle-extensions-plugin: fix output of exceptions with multiple nested suppressed exceptions
194195

195196
v1.71
196197
* Add CI jobs with nightly and RC Gradle versions

plugins/gradle-extensions-plugin/src/main/kotlin/com/github/vlsi/gradle/ThrowablePrinter.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,27 +207,31 @@ class ThrowablePrinter {
207207
}
208208

209209
val nextIndent = if (hideThrowable) indent else " $indent"
210-
throwable.suppressed.forEach {
211-
queue += Work(it, nextIndent, "Suppressed: ", ourStack)
212-
}
213210

214211
fun addNextExceptions(prefix: String, causes: Iterable<Throwable>) {
215212
val skipMessage = causes is List<*> && causes.size == 1
213+
val errors = mutableListOf<Work>()
216214
for ((i, cause) in causes.withIndex()) {
217215
val causeIndex = if (skipMessage) "" else "$prefix ${i + 1}: "
218-
queue += Work(cause, nextIndent, causeIndex, ourStack)
216+
errors += Work(cause, nextIndent, causeIndex, ourStack)
217+
}
218+
for(work in errors.asReversed()) {
219+
queue.addFirst(work)
219220
}
220221
}
221222
if (throwable is MultiCauseException) {
222223
addNextExceptions("Cause", throwable.causes)
223224
} else {
224225
throwable.cause?.let {
225-
queue += Work(it, nextIndent, "Caused by: ", ourStack)
226+
queue.addFirst(Work(it, nextIndent, "Caused by: ", ourStack))
226227
}
227228
}
228229
if (throwable is SQLException) {
229230
addNextExceptions("Next exception", Iterable { throwable.iterator() })
230231
}
232+
throwable.suppressed.asList().asReversed().forEach {
233+
queue.addFirst(Work(it, nextIndent, "Suppressed: ", ourStack))
234+
}
231235
val lastFrame = if (hideStacktrace || ourStack?.isEmpty() == null) {
232236
continue
233237
} else if (causedBy?.isNotEmpty() == true) {

0 commit comments

Comments
 (0)