        sm2))))
 
 
-(defn epoch-counter
+
+(defn wrapper-epoch-counter
   "This wrapper increments a counter on every transition.
   Useful to determine whether the state machine is progressing."
   [handler]




(comment

  (defn error-state
    [handler]
    (fn [{:keys [state epoch] :as sm}]
      (try
        (-> (handler sm)
            ;; clear error flag
            (update :latest-errors dissoc state));; TODO: dissoc-in
        (catch Throwable x
          (-> sm
              (assoc-in  [:latest-errors :from-state] state)
              (update-in [:latest-errors state :repeated] (fnil inc 0))
              (update-in [:latest-errors state]
                         #(merge % {:error-epoch epoch
                                    :error       x}))
              (assoc :state :machina/error))))))


  (defn error-dispatch
    [{{:keys [from-state]} :latest-errors
      error-policies :error-policies :as sm}]
    (if-let [policy (or (get error-policies from-state) (get error-policies :machina/default))]
      ;; TODO: multimethod dispatch by type?
      (let [{:keys [retry-delay]} policy
            nap (or (get-in sm [:latest-errors from-state :sleeper]) (apply safely/sleeper retry-delay))]
        (-> sm
            (assoc-in [:latest-errors from-state :sleeper] nap)
            (assoc :sleeper {:nap nap :return-state from-state})
            (assoc :state :machina/sleep))

        )
      (throw (ex-info "no default error policy" sm)))
    )


  (comment

        :wrappers
        [#'epoch-counter #'log-state-change #'error-state]}))))


  (defn- wrapper
    ([] identity)
