mirror of
https://github.com/penpot/penpot.git
synced 2026-11-26 21:00:32 +00:00
✨ 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:
parent
3bd549a146
commit
deffc02098
@ -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]
|
||||
|
||||
@ -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" {}))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user