0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 16:21:57 -05:00

Report errors on events.

This commit is contained in:
Andrey Antukh 2021-05-05 15:22:04 +02:00 committed by Andrés Moya
parent abb244c940
commit 3ce4769e8d
2 changed files with 66 additions and 38 deletions

View file

@ -76,6 +76,7 @@
{:status 500
:body {:type :server-error
:code :assertion
:data (-> edata
(assoc :explain (explain-error edata))
(dissoc :data))}}))
@ -103,6 +104,7 @@
:cause error)
{:status 500
:body {:type :server-error
:code :unexpected
:hint (ex-message error)
:data edata}}))))
@ -132,7 +134,8 @@
:else
{:status 500
:body {:type :server-timeout
:body {:type :server-error
:code :psql-exception
:hint (ex-message error)
:state state}})))

View file

@ -226,8 +226,9 @@
[error]
(ts/schedule
(st/emitf
(dm/show {:content "Unexpected validation error (server side)."
:type :error})))
(dm/show {:content "Unexpected validation error."
:type :error
:timeout 3000})))
;; Print to the console some debug info.
(js/console.group "Validation Error")
@ -243,58 +244,82 @@
;; assertion (assertion that is preserved on production builds). From
;; the user perspective this should be treated as internal error.
(defmethod ptk/handle-error :assertion
[{:keys [data stack message context] :as error}]
(ts/schedule
(st/emitf (dm/show {:content "Internal error: assertion."
:type :error})))
[{:keys [data stack message hint context] :as error}]
(let [message (or message hint)
context (str/fmt "ns: '%s'\nname: '%s'\nfile: '%s:%s'"
(:ns context)
(:name context)
(str cfg/public-uri "/js/cljs-runtime/" (:file context))
(:line context))]
(ts/schedule
(st/emitf
(dm/show {:content "Internal error: assertion."
:type :error
:timeout 3000})
(ptk/event ::ev/event
{::ev/type "exception"
::ev/name "assertion-error"
:message message
:context context
:trace stack})))
;; Print to the console some debugging info
(js/console.group message)
(js/console.info (str/format "ns: '%s'\nname: '%s'\nfile: '%s:%s'"
(:ns context)
(:name context)
(str cfg/public-uri "/js/cljs-runtime/" (:file context))
(:line context)))
(js/console.groupCollapsed "Stack Trace")
(js/console.info stack)
(js/console.groupEnd "Stack Trace")
(js/console.error (with-out-str (expound/printer data)))
(js/console.groupEnd message))
;; Print to the console some debugging info
(js/console.group message)
(js/console.info context)
(js/console.groupCollapsed "Stack Trace")
(js/console.info stack)
(js/console.groupEnd "Stack Trace")
(js/console.error (with-out-str (expound/printer data)))
(js/console.groupEnd message)))
;; This happens when the backed server fails to process the
;; request. This can be caused by an internal assertion or any other
;; uncontrolled error.
(defmethod ptk/handle-error :server-error
[{:keys [data] :as error}]
(ts/schedule
(st/emitf (dm/show
{:content "Something wrong has happened (on backend)."
:type :error})))
[{:keys [data hint] :as error}]
(let [hint (or hint (:hint data) (:message data))
info (with-out-str (pprint (dissoc data :explain)))
expl (:explain data)]
(ts/schedule
(st/emitf
(dm/show {:content "Something wrong has happened (on backend)."
:type :error
:timeout 3000})
(ptk/event ::ev/event
{::ev/type "exception"
::ev/name "server-error"
:hint hint
:info info
:explain expl})))
(js/console.group "Internal Server Error:")
(js/console.error "hint:" (or (:hint data) (:message data)))
(js/console.info
(with-out-str
(pprint (dissoc data :explain))))
(when-let [explain (:explain data)]
(js/console.error explain))
(js/console.groupEnd "Internal Server Error:"))
(js/console.group "Internal Server Error:")
(js/console.error "hint:" hint)
(js/console.info info)
(when expl (js/console.error expl))
(js/console.groupEnd "Internal Server Error:")))
(defmethod ptk/handle-error :default
[error]
(if (instance? ExceptionInfo error)
(ptk/handle-error (ex-data error))
(do
(let [stack (.-stack error)
hint (or (ex-message error)
(:hint error)
(:message error))]
(ts/schedule
(st/emitf (dm/assign-exception error)))
(st/emitf
(dm/assign-exception error)
(ptk/event ::ev/event
{::ev/type "exception"
::ev/name "unexpected-error"
:message hint
:trace (.-stack error)})))
(js/console.group "Internal error:")
(js/console.log "hint:" (or (ex-message error)
(:hint error)
(:message error)))
(js/console.log "hint:" hint)
(ex/ignoring
(js/console.error (clj->js error))
(js/console.error "stack:" (.-stack error)))
(js/console.error "stack:" stack))
(js/console.groupEnd "Internal error:"))))
(defonce uncaught-error-handler