Welcome! Please see the About page for a little more info on how this works.

+2 votes
in Metadata by

Sometimes I need to interact with the base exception information on an ExceptionInfo (such as .setStackTrace). The core function ex-info doesn't type hint either arity, so to avoid reflection warnings, I must specify ^ExceptionInfo when using the results of the call:

(let [old-ex (Exception. "asdf")
      new-ex (ex-info "example" {})]
  (doto  ^ExceptionInfo new-ex (.setStackTrace (.getStackTrace old-ex))))

Adding type hints to ex-info would neatly solve this for all such uses (including the uses in Clojure core, ex-data etc).

I can create a patch if there's interest.

2 Answers

+1 vote
by
selected by
 
Best answer

Jira ticket https://clojure.atlassian.net/browse/CLJ-2815 has been created to track the issue.

by
Thank you! And thank you for the patch!
0 votes
by

Seems like ex-info mostly constructs a thing that is thrown and then caught in a catch block, where this type hint would not help?

by
That’s true, which is why I didn’t mention that case. I’m thinking about the disconnect between saying (Exception. “some message”) which propagates its type for interop and (ex-info “some message” {}) which does not.

We’ve run into this in a couple places in my company’s code base and it’s not a deal breaker but it’s annoying enough that it seems worth changing in core without any negatives.
...