Skip to content

Commit f104028

Browse files
committed
flatten suppressed exception list
1 parent 84a8fc7 commit f104028

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

  • lib/src/main/kotlin/org/veupathdb/lib/compute/platform/intern/minio

lib/src/main/kotlin/org/veupathdb/lib/compute/platform/intern/minio/MinIOHax.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,25 @@ internal object MinIOHax {
4040
*/
4141
context(log: Logger)
4242
fun <T> withRetries(actionMsg: () -> String, action: () -> T): T {
43-
var lastError: S34KError? = null
43+
val errors = ArrayList<S34KError>(RetryCount)
44+
var msg: String? = null
4445

4546
for (i in 1..RetryCount) {
4647
try {
4748
return action()
4849
} catch (e: S34KError) {
49-
log.warn("failed {} time(s) to {}", i, actionMsg())
50-
51-
if (lastError != null)
52-
e.addSuppressed(lastError)
53-
54-
lastError = e
50+
if (msg == null)
51+
msg = actionMsg()
5552

53+
log.warn("failed {} time(s) to {}", i, msg)
54+
errors.add(e)
5655
sleep()
5756
}
5857
}
5958

60-
log.error("failed {} time(s) to {}", RetryCount, actionMsg())
61-
throw lastError!!
59+
log.error("failed {} time(s) to {}", RetryCount, msg)
60+
throw errors.last()
61+
.apply { errors.forEach { if (it != this) addSuppressed(it) } }
6262
}
6363

6464
/**

0 commit comments

Comments
 (0)