clojure-dev

2025-03-24T14:57:00.722379Z

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

2025-03-25T18:12:11.344519Z

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.

➕ 1
Alex Miller (Clojure team) 2025-03-24T15:18:38.622549Z

Like the ex-data?

2025-03-24T15:19:47.339379Z

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

2025-03-24T15:20:02.427469Z

"caught bad number" doesn't appear in the message in the repl

2025-03-24T15:20:34.586779Z

compared to something that might be like "caught bad number - Divide by zero"

2025-03-24T15:20:50.578209Z

or any number of other alternatives

2025-03-24T15:21:57.270699Z

the jira ticket didn't include reasoning for this, and i've wondered on and off since 1.10 released

Alex Miller (Clojure team) 2025-03-24T15:22:30.318339Z

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

👍 1
Alex Miller (Clojure team) 2025-03-24T15:25:55.679789Z

In your code you have the option to not chain the cause there and “become” the new root

2025-03-24T15:26:18.249689Z

Right, that's always true

2025-03-24T15:27:24.444789Z

clojure is generally helpfully verbose with these things (spec errors are an example), so not including the info felt deliberate

Alex Miller (Clojure team) 2025-03-24T15:29:32.725259Z

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

Alex Miller (Clojure team) 2025-03-24T15:31:31.553759Z

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.

👍 1