From deffc0209898dd84f65d82fbf3bc15c54b1b9b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?andr=C3=A9s=20gonz=C3=A1lez?= Date: Tue, 24 Nov 2026 09:47:50 +0100 Subject: [PATCH] :sparkles: 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 --- common/src/app/common/exceptions.cljc | 15 +++++++++++++- common/test/common_tests/exceptions_test.cljc | 20 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/exceptions.cljc b/common/src/app/common/exceptions.cljc index f27d1d531d..7973d32a99 100644 --- a/common/src/app/common/exceptions.cljc +++ b/common/src/app/common/exceptions.cljc @@ -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] diff --git a/common/test/common_tests/exceptions_test.cljc b/common/test/common_tests/exceptions_test.cljc index 6f9df8da60..f107445367 100644 --- a/common/test/common_tests/exceptions_test.cljc +++ b/common/test/common_tests/exceptions_test.cljc @@ -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" {}))