From 6fb214a408fc1ab8a35e0e8e0db5deb73750c934 Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Sat, 30 Nov 2024 23:51:28 +0100 Subject: [PATCH] Unwrap Failsafe target exception Signed-off-by: Paolo Di Tommaso --- src/main/groovy/io/seqera/wave/util/Retryable.groovy | 7 ++++++- src/test/groovy/io/seqera/wave/util/RetryableTest.groovy | 6 ++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/groovy/io/seqera/wave/util/Retryable.groovy b/src/main/groovy/io/seqera/wave/util/Retryable.groovy index db4a6f9eb..703d33900 100644 --- a/src/main/groovy/io/seqera/wave/util/Retryable.groovy +++ b/src/main/groovy/io/seqera/wave/util/Retryable.groovy @@ -24,6 +24,7 @@ import java.util.function.Consumer import java.util.function.Predicate import dev.failsafe.Failsafe +import dev.failsafe.FailsafeException import dev.failsafe.RetryPolicy import dev.failsafe.RetryPolicyBuilder import dev.failsafe.event.EventListener @@ -137,7 +138,11 @@ class Retryable { R apply(CheckedSupplier action) { final policy = retryPolicy() - return Failsafe.with(policy).get(action) + try { + return Failsafe.with(policy).get(action) + } catch (FailsafeException e) { + throw e.cause + } } static Retryable of(Config config) { diff --git a/src/test/groovy/io/seqera/wave/util/RetryableTest.groovy b/src/test/groovy/io/seqera/wave/util/RetryableTest.groovy index 70c2fd6d7..3828dc8c1 100644 --- a/src/test/groovy/io/seqera/wave/util/RetryableTest.groovy +++ b/src/test/groovy/io/seqera/wave/util/RetryableTest.groovy @@ -22,9 +22,7 @@ import spock.lang.Specification import java.time.Duration -import dev.failsafe.FailsafeException import groovy.util.logging.Slf4j - /** * * @author Paolo Di Tommaso @@ -65,8 +63,8 @@ class RetryableTest extends Specification { when: retryable.apply(()-> {throw new IOException("Oops failed!")}) then: - def e = thrown(FailsafeException) - e.cause instanceof IOException + def e = thrown(IOException) + e.message == 'Oops failed!' } def 'should validate config' () {