Fork me on GitHub
#yada
<
2017-01-07
>
martinklepsch10:01:40

This is not really yada related but probably people here can give some advice anyways: I’m building pipeline system and want to add something like interceptors (in contrast to with-db-conn macros and similar) that inject stuff into the pipeline’s context. One thing I’m wondering is how error handling is implemented with interceptors. E.g. an interceptor takes a resource from a pool. How do I make sure it’s returned on failure (or marked as broken)?

martinklepsch10:01:54

One option I can think of is an inteceptor impl like this:

(defprotocol Intercept
  (before [this ctx])
  (after [this ctx])
  (error [this ctx exception]))
but I haven’t ever implemented a system like this so I’m looking for someone who has and may be able to give feedback

lmergen11:01:22

@martinklepsch is this perhaps something that could be addressed using manifold’s error mechanism ?

lmergen11:01:43

as in, i would almost think of an interceptor chain as a manifold stream

martinklepsch11:01:25

I don’t need async right now, more interested in using it to add “do before” “do after” stuff to my pipeline

lmergen11:01:27

so yeah, in your interceptor protocol impl, i would just try to model the try / catch / finally mechanism, which has proven to be powerful 🙂

martinklepsch11:01:03

@lmergen how do you mean model try/catch/finally

lmergen11:01:10

so, in your example, it would become

(defprotocol Intercept
  (before [this ctx])
  (after [this ctx])
  (catch [this ctx exception])
  (finally [this ctx]))

lmergen11:01:27

at least, this feels like a familiar mechanism to handle error reporting

martinklepsch11:01:19

Ah, I see what you mean, that makes sense, thanks!