Skip to content

Commit 2b72880

Browse files
committed
implant: subscribe "unhandledrejection" to report failed promises
1 parent c1d4af1 commit 2b72880

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/implant/dirac/implant/reporter.cljs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[chromex.logging :refer-macros [log warn error group group-end]]
44
[dirac.utils :as utils]))
55

6-
; -- handling exceptions ----------------------------------------------------------------------------------------------------
6+
; -- handling global exceptions ---------------------------------------------------------------------------------------------
77

88
(defn devtools-exception-handler! [_message _source _lineno _colno e]
99
(let [text (str "Internal Dirac Error: DevTools code has thrown an unhandled exception\n" (utils/format-error e))]
@@ -13,5 +13,19 @@
1313
(defn register-global-exception-handler! []
1414
(oset js/window ["onerror"] devtools-exception-handler!))
1515

16+
; -- handling unhandled rejections in promises ------------------------------------------------------------------------------
17+
18+
(defn devtools-unhandled-rejection-handler! [event]
19+
(let [reason (oget event "reason")
20+
text (str "Internal Dirac Error: DevTools code has thrown an unhandled rejection (in promise)\n"
21+
(utils/format-error reason))]
22+
(ocall (oget js/window "dirac") "addConsoleMessageToMainTarget" "error" text)))
23+
24+
(defn register-unhandled-rejection-handler! []
25+
(.addEventListener js/window "unhandledrejection" devtools-unhandled-rejection-handler!))
26+
27+
; -- installation -----------------------------------------------------------------------------------------------------------
28+
1629
(defn install! []
17-
(register-global-exception-handler!))
30+
(register-global-exception-handler!)
31+
(register-unhandled-rejection-handler!))

0 commit comments

Comments
 (0)