yada icon indicating copy to clipboard operation
yada copied to clipboard

FIX error-interceptor-ctx keeps ctx state of non-erroring interceptor…

Open boxxxie opened this issue 3 years ago • 0 comments

…s or :ctx from cause

previous: (:ctx data) was used to get ctx, or ctx started from scratch on error for error-interceptors-chain

however, if a resource has (throw (ex-info "..." {:ctx yada-ctx})) then the :ctx is likely on the cause (ex-cause e), so (some->> e ex-cause ex-data :ctx) gets the ctx if a user added it to ex-info

this isn't good enough, as if an error is thrown without user doing (try catch (throw (ex-info ...)) then we don't have the ctx anymore, but we probably want the ctx for error reporting

the below code iterates through each interceptor and returns the last ctx state before the interceptor chain throws. so now our error-interceptor-chain has whatever ctx that existed when the error happened.

(let [partial-ctx
      @(d/loop [ctx ctx
                    [interceptor & interceptors-rest] (:interceptor-chain ctx)]
               (let [next-ctx (interceptor ctx)]
                 (if (instance? manifold.deferred.ErrorDeferred next-ctx)
                     ctx
                   (d/recur next-ctx interceptors-rest))))])

boxxxie avatar Jul 20 '22 16:07 boxxxie