Skip to content

Commit

Permalink
implant: subscribe "unhandledrejection" to report failed promises
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin committed Aug 16, 2016
1 parent c1d4af1 commit 2b72880
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/implant/dirac/implant/reporter.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[chromex.logging :refer-macros [log warn error group group-end]]
[dirac.utils :as utils]))

; -- handling exceptions ----------------------------------------------------------------------------------------------------
; -- handling global exceptions ---------------------------------------------------------------------------------------------

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

; -- handling unhandled rejections in promises ------------------------------------------------------------------------------

(defn devtools-unhandled-rejection-handler! [event]
(let [reason (oget event "reason")
text (str "Internal Dirac Error: DevTools code has thrown an unhandled rejection (in promise)\n"
(utils/format-error reason))]
(ocall (oget js/window "dirac") "addConsoleMessageToMainTarget" "error" text)))

(defn register-unhandled-rejection-handler! []
(.addEventListener js/window "unhandledrejection" devtools-unhandled-rejection-handler!))

; -- installation -----------------------------------------------------------------------------------------------------------

(defn install! []
(register-global-exception-handler!))
(register-global-exception-handler!)
(register-unhandled-rejection-handler!))

0 comments on commit 2b72880

Please sign in to comment.