Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

boxxxie
Copy link
Contributor

@boxxxie boxxxie commented Jul 20, 2022

…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))))])

…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))))])
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant