Skip to content

Not retrying when Exception is thrown #13

@jvtrigueros

Description

@jvtrigueros

I have existing functions that I'm attempting to decorate as retriable, but I'm noticing that retry is not triggered when java.lang.Exception is thrown, I'm not sure if this is an issue with the upstream dependency, but I can repro it with this code:

(require '[resilience4clj-retry.core :as r])
(def retry (r/create "test-retry"))
(r/listen-event retry
                :RETRY
                (fn [_] (println "retrying...")))

;; 1. Exception
(def retriable-fn
  (r/decorate
    (fn [] (throw (Exception. "not good")))
    retry))

(retriable-fn)
;; Execution error at retry/fn (retry.clj:4).
;; not good

;; 2. ex-info
(def retriable-fn
  (r/decorate
    (fn [] (throw (ex-info "not good" {})))
    retry))

(retriable-fn)
;; retrying...
;; retrying...
;; Execution error (ExceptionInfo) at retry/fn (retry.clj:3).
;; not good

;; 3. Exception caught and re-thrown as ex-info
(def retriable-fn
  (r/decorate
    (fn [] (throw (ex-info "not good" {} (Exception. "not good"))))
    retry))

(retriable-fn)
;; retrying...
;; retrying...
;; Execution error at retry/fn (retry.clj:3).
;; not good
  1. Throws java.lang.Exception and retry logic is never executed
  2. Works as expected
  3. Also works, but requires extra layer of try-catch

What am I missing here? Is there a config that I must add to catch java.lang.Exception?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions