Clojure

Provide a type predicate for ex-info?

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.9
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test

Description

A type predicate for ExceptionInfo would be as useful when writing specs as the other nice additions landing in Clojure 1.9 (e.g. nat-int?, pos-int?, etc).

Activity

Hide
Alex Miller added a comment -

It would be helpful to list an example of some code where this would come in handy (I think examples do exist in catch handling) and to give some indication of how common it is.

Show
Alex Miller added a comment - It would be helpful to list an example of some code where this would come in handy (I think examples do exist in catch handling) and to give some indication of how common it is.
Hide
Christian Romney added a comment - - edited

One place where it can be useful is specing data that's pulled from a channel. http://swannodette.github.io/2013/08/31/asynchronous-error-handling. David's example immediately throws the exception via the <? macro, but the fact that exception info might be put on the channel at all means it can be seen by functions we might have in a transducer. These functions can leverage spec, where this predicate would come in very handy. I'd paste code, but the example immediately at hand is proprietary. Is this a sufficiently good description, or does the case need more support?

Also, while David's example is CLJS I've used this pattern in Clojure core.async code (e.g. asynchronous Pedestal interceptors).

Show
Christian Romney added a comment - - edited One place where it can be useful is specing data that's pulled from a channel. http://swannodette.github.io/2013/08/31/asynchronous-error-handling. David's example immediately throws the exception via the <? macro, but the fact that exception info might be put on the channel at all means it can be seen by functions we might have in a transducer. These functions can leverage spec, where this predicate would come in very handy. I'd paste code, but the example immediately at hand is proprietary. Is this a sufficiently good description, or does the case need more support? Also, while David's example is CLJS I've used this pattern in Clojure core.async code (e.g. asynchronous Pedestal interceptors).
Hide
Christian Romney added a comment -

Also, from an aesthetic[1] point of view adding a type predicate (ex-info?) for a pretty important core Clojure abstraction that already has a constructor (ex-info) and an accessor (ex-data) just seems to round out / complete the API. Not sure how that compelling you or Rich might find that argument, but I figured it couldn't hurt the case.

[1] My sense of aesthetic here is colored by some of the ideas in Mitch Wand & Dan Friedman's Essentials of Programming Languages.

Show
Christian Romney added a comment - Also, from an aesthetic[1] point of view adding a type predicate (ex-info?) for a pretty important core Clojure abstraction that already has a constructor (ex-info) and an accessor (ex-data) just seems to round out / complete the API. Not sure how that compelling you or Rich might find that argument, but I figured it couldn't hurt the case. [1] My sense of aesthetic here is colored by some of the ideas in Mitch Wand & Dan Friedman's Essentials of Programming Languages.

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated: