Skip to content

Commit

Permalink
Unwrap Failsafe target exception
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
  • Loading branch information
pditommaso committed Dec 1, 2024
1 parent 2fd351d commit 6fb214a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/main/groovy/io/seqera/wave/util/Retryable.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,7 +138,11 @@ class Retryable<R> {

R apply(CheckedSupplier<R> action) {
final policy = retryPolicy()
return Failsafe.with(policy).get(action)
try {
return Failsafe.with(policy).get(action)
} catch (FailsafeException e) {
throw e.cause
}
}

static <T> Retryable<T> of(Config config) {
Expand Down
6 changes: 2 additions & 4 deletions src/test/groovy/io/seqera/wave/util/RetryableTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 <paolo.ditommaso@gmail.com>
Expand Down Expand Up @@ -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' () {
Expand Down

0 comments on commit 6fb214a

Please sign in to comment.