hey alex, remember why you chose to only print the cause and nothing else in the 1.10 patch CLJ-2420? https://github.com/clojure/clojure/commit/817abb3d0ca3b7ee80cfe17b5cfe3ea8306f0720
In general, most wrapped exceptions don’t add additional info and the root cause message is the most useful.I'm not sure I'd agree here though. The root cause can sometimes lack relevant context and be something quite primitive - such as in the example here with the "Divide by zero". I do agree it may get confusing how you concat them together though. I guess the idea though is that you can still find this if you just look at the actual stack trace.
Like the ex-data?
user=> (defn div-by-0 [a] (/ a 0))
#'user/div-by-0
user=> (defn cool-div [a]
#_=> (try (div-by-0 a)
#_=> (catch Exception e
#_=> (throw (ex-info "caught bad number" {:a a} e)))))
#'user/cool-div
user=> (cool-div 100)
Execution error (ArithmeticException) at user/div-by-0 (REPL:1).
Divide by zero
"caught bad number" doesn't appear in the message in the repl
compared to something that might be like "caught bad number - Divide by zero"
or any number of other alternatives
the jira ticket didn't include reasoning for this, and i've wondered on and off since 1.10 released
Well, where does that end? In general, most wrapped exceptions don’t add additional info and the root cause message is the most useful. We have been doing it that way in pst since forever so mostly followed that
In your code you have the option to not chain the cause there and “become” the new root
Right, that's always true
clojure is generally helpfully verbose with these things (spec errors are an example), so not including the info felt deliberate
If I were going to think about this as a problem, something like “wrappers can’t displace an improved message while retaining exception chain”, I can imagine defining some “protocol” (I don’t mean Clojure protocols, but some mechanism) for establishing a wrapper message as the preferred message bearer
Like a well known ex-data key that, when found, becomes the reported message. I don’t think combining multiple messages from the chain ever ends up in a satisfying place.