MichaelDrogalis / dire

Erlang-style supervisor error handling for Clojure
483 stars 20 forks source link

Support slingshot throwable matching in with-handler #9

Closed glenjamin closed 10 years ago

glenjamin commented 11 years ago

From a cursory glance through the dire and slingshot code, I can't see a way to slot this in nicely.

I think what's needed is some of the code from slingshot's transform-catch, but at the moment the helper functions we'd need are hidden away in a letfn form.

https://github.com/scgilardi/slingshot/blob/master/src/slingshot/support.clj#L142

MichaelDrogalis commented 11 years ago

Since we're using try+ inside Dire, perhaps we can catch Object as seen in the second example? (https://github.com/scgilardi/slingshot#usage) It feels hacky though.

I still think there's something to implementing an arbitrary function dispatcher to help solve this problem. Having a lot of trouble visualizing how it should work though.

At any rate, I absolutely want to support Slingshot.

MichaelDrogalis commented 11 years ago

I added an implementation for arbitrary function dispatch on develop. While one still has to perform some set up for it to work well with Slingshot, it's a step in the right direction. https://github.com/MichaelDrogalis/dire/blob/develop/test/dire/test/dispatch_test.clj#L6

Another example: https://gist.github.com/MichaelDrogalis/5377029

@oneness

glenjamin commented 11 years ago

I think the only way to get slingshot sugar without just copy-pasting the matching functions, is to get slignshot to expose a catch+ function, which does the handling as seen at https://github.com/scgilardi/slingshot/blob/master/src/slingshot/support.clj#L179

Dire would then be able to do something like (catch Throwable e (catch+ e catch-clauses))

MichaelDrogalis commented 11 years ago

Yeah, after sleeping on it, I think you're right. There's also no reason to have arbitrary function dispatch if we have full slingshot support, given that for the custom dispatch to be useful, you'd be using throw+ anyhow.

I'll play around with copy-pasting the code in to make sure our assumptions are correct, then I'll talk to Phil about perhaps exposing catch+.

MichaelDrogalis commented 11 years ago

I am stuck on this, for the record.

glenjamin commented 11 years ago

I'm still intending to have a crack at this, when I get some time!

MichaelDrogalis commented 11 years ago

Certainly no rush!

MichaelDrogalis commented 10 years ago

With #17, this is done. :) Thanks @dparis !

glenjamin commented 10 years ago

Awesome work! I'd just put this back on my todo list - now I can cross it off already :)

MichaelDrogalis commented 10 years ago

Doesn't get much better than that! It's out on 0.5.0-SNAPSHOT, and will be released as 0.5.0 tomorrow morning.

dparis commented 10 years ago

Glad it's working out! Let me know if you run across any problems with the new functionality.