✨ Print the cause of an error in the frontend error report (#13274)

WASM errors are thrown as an ex-info whose cause is the original failure
(the trap, `RuntimeError: unreachable`, `memory access out of bounds`,
`Aborted(OOM)`). The CLJS `format-throwable` printed only the ex-data and
the stack, so the report said where a WASM call failed but never why.

Add a "Caused by:" block with the cause message, printed on its own since
only V8 starts `.stack` with it, followed by its formatted data and stack.

Relates to #12910

AI-assisted-by: claude-opus-5-5
This commit is contained in:
andrés gonzález 2026-11-24 09:47:50 +01:00 committed by GitHub
parent 3bd549a146
commit deffc02098
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 1 deletions

View File

@ -296,7 +296,20 @@
(when head
(println head))
(doseq [line (if trace-length (take trace-length tail) tail)]
(println line)))))))
(println line))))
;; The cause holds the original failure, e.g. the WASM trap behind a
;; `:wasm-error` (`RuntimeError: unreachable`, `Aborted(OOM)`). Its
;; message is printed on its own: only V8 starts `.stack` with it.
(when-let [inner (ex-cause cause)]
(let [message (if (ex-data inner) (ex-message inner) (str inner))]
(println)
(println "Caused by:")
(println "--------------------")
(println (truncate message max-message-length))
(when (or (ex-data inner) (.-stack inner))
(println)
(print (format-throwable inner :trace-length trace-length))))))))
(defn first-line
[s]

View File

@ -50,6 +50,26 @@
(t/is (some? msg))
(t/is (<= (count msg) (+ ex/max-message-length 16))))))
#?(:cljs
(t/deftest format-throwable-includes-the-cause-test
(let [cause (js/Error. "memory access out of bounds")
out (ex/format-throwable (ex-info "WASM Error (wasm-critical)"
{:type :wasm-error}
cause))]
(t/is (str/includes? out "Caused by:"))
(t/is (str/includes? out "memory access out of bounds")))))
#?(:cljs
(t/deftest format-throwable-includes-a-non-error-cause-test
(let [out (ex/format-throwable (ex-info "outer" {} "Aborted(OOM)"))]
(t/is (str/includes? out "Caused by:"))
(t/is (str/includes? out "Aborted(OOM)")))))
#?(:cljs
(t/deftest format-throwable-omits-the-cause-block-without-a-cause-test
(t/is (not (str/includes? (ex/format-throwable (ex-info "boom" {}))
"Caused by:")))))
#?(:cljs
(t/deftest format-throwable-honors-trace-length-test
(let [full (ex/format-throwable (ex-info "boom" {}))