diff --git a/backend/resources/error-report.tmpl b/backend/resources/error-report.tmpl index 2ff0abb1f..397b83b02 100644 --- a/backend/resources/error-report.tmpl +++ b/backend/resources/error-report.tmpl @@ -13,15 +13,40 @@ } pre { margin: 0px; + line-height: 17px; } + + main { + margin: 20px; + } + + nav { + position: fixed; + width: 100vw; + top: 0; + left: 0; + padding: 5px 20px; + display: flex; + background: #e3e3e3; + } + + nav > div { + text-transform: uppercase; + font-weight: bold; + } + + nav > div:not(:last-child) { + margin-right: 10px; + } + * { font-family: "JetBrains Mono", monospace; font-size: 12px; } .table { + margin-top: 40px; display: flex; flex-direction: column; - margin: 10px; } .table-row { @@ -34,6 +59,9 @@ font-weight: 600; width: 60px; padding: 4px; + + padding-top: 40px; + margin-top: -40px; } .table-val { @@ -57,147 +85,68 @@ -
-
-
ERID:
-
{{id}}
-
- {% if profile-id %} -
-
PFID:
-
{{profile-id}}
-
- {% endif %} - {% if user-agent %} -
-
UAGT:
-
{{user-agent}}
-
- {% endif %} - - {% if frontend-version %} -
-
FVER:
-
{{frontend-version}}
-
- {% endif %} - -
-
BVER:
-
{{version}}
-
- - {% if host %} -
-
HOST:
-
{{host}}
-
- {% endif %} - - {% if tenant %} -
-
ENV:
-
{{tenant}}
-
- {% endif %} - - {% if public-uri %} -
-
PURI:
-
{{public-uri}}
-
- {% endif %} - - {% if type %} -
-
TYPE:
-
{{type}}
-
- {% endif %} - - {% if code %} -
-
CODE:
-
{{code}}
-
- {% endif %} - - {% if error %} -
-
CLSS:
-
{{error.class}}
-
- {% endif %} - - {% if hint %} -
-
HINT:
-
{{hint}}
-
- {% endif %} - - {% if method %} -
-
PATH:
-
{{method|upper}} {{path}}
-
- {% endif %} - -
(go to explain)
-
(go to edata)
-
(go to trace)
- - {% if params %} -
-
PARAMS:
-
-
{{params}}
-
-
+ +
+
+
+
CONTEXT:
+
+
{{context}}
+
+
- {% if spec-problems %} -
-
SPEC PROBLEMS:
-
-
{{spec-problems}}
+ {% if params %} +
+
PARAMS:
+
+
{{params}}
+
-
- {% endif %} + {% endif %} - {% if cause %} -
-
TRACE:
-
-
{{cause}}
+ + {% if data %} +
+
ERROR DATA:
+
+
{{data}}
+
-
- {% elif trace %} -
-
TRACE:
-
-
{{trace}}
+ {% endif %} + + {% if spec-problems %} +
+
SPEC PROBLEMS:
+
+
{{spec-problems}}
+
-
- {% elif error %} -
-
TRACE:
-
-
{{error.trace}}
+ {% endif %} + + {% if trace %} +
+
TRACE:
+
+
{{trace}}
+
+ {% endif %}
- {% endif %} -
+
diff --git a/backend/src/app/http/debug.clj b/backend/src/app/http/debug.clj index d30257b65..1456750e7 100644 --- a/backend/src/app/http/debug.clj +++ b/backend/src/app/http/debug.clj @@ -11,6 +11,7 @@ [app.common.spec :as us] [app.common.transit :as t] [app.common.uuid :as uuid] + [clojure.pprint :as ppr] [app.config :as cf] [app.db :as db] [app.util.template :as tmpl] @@ -99,7 +100,6 @@ (ex/raise :type :validation :code :invalid-arguments)))) - (defn retrieve-error [{:keys [pool]} request] (letfn [(parse-id [request] @@ -107,14 +107,23 @@ id (us/uuid-conformer id)] (when (uuid? id) id))) + (retrieve-report [id] (ex/ignoring - (when-let [{:keys [content] :as row} (db/get-by-id pool :server-error-report id)] - (assoc row :content (db/decode-transit-pgobject content))))) + (some-> (db/get-by-id pool :server-error-report id) :content db/decode-transit-pgobject))) - (render-template [{:keys [content] :as report}] - (some-> (io/resource "error-report.tmpl") - (tmpl/render content)))] + (render-template [report] + (binding [ppr/*print-right-margin* 300] + (let [context (dissoc report :trace :cause :params :data :spec-prob :spec-problems) + params {:context (with-out-str (ppr/pprint context)) + :data (:data report) + :trace (or (:cause report) + (:trace report) + (some-> report :error :trace)) + :params (:params report)}] + (-> (io/resource "error-report.tmpl") + (tmpl/render params))))) + ] (when-not (authorized? pool request) (ex/raise :type :authentication diff --git a/backend/src/app/http/errors.clj b/backend/src/app/http/errors.clj index e4ff27bcf..d1205c465 100644 --- a/backend/src/app/http/errors.clj +++ b/backend/src/app/http/errors.clj @@ -30,14 +30,13 @@ :hint (or (:hint data) (ex-message error)) :params (l/stringify-data (:params request)) :spec-problems (some-> data ::s/problems) + :data (some-> data (dissoc ::s/problems)) :ip-addr (parse-client-ip request) :profile-id (:profile-id request)} (let [headers (:headers request)] {:user-agent (get headers "user-agent") - :frontend-version (get headers "x-frontend-version" "unknown")}) - - (dissoc data ::s/problems)))) + :frontend-version (get headers "x-frontend-version" "unknown")})))) (defmulti handle-exception (fn [err & _rest] @@ -56,8 +55,7 @@ (defmethod handle-exception :validation [err _] (let [edata (ex-data err)] - {:status 400 - :body (dissoc edata ::s/problems)})) + {:status 400 :body edata})) (defmethod handle-exception :assertion [error request] diff --git a/backend/src/app/http/session.clj b/backend/src/app/http/session.clj index 288896140..f341f91da 100644 --- a/backend/src/app/http/session.clj +++ b/backend/src/app/http/session.clj @@ -73,6 +73,7 @@ (if-let [{:keys [id profile-id] :as session} (retrieve-from-request cfg request)] (do (a/>!! (::events-ch cfg) id) + (l/set-context! {:profile-id profile-id}) (handler (assoc request :profile-id profile-id))) (handler request)))) diff --git a/backend/src/app/loggers/database.clj b/backend/src/app/loggers/database.clj index 20b9625c2..6bbc1297e 100644 --- a/backend/src/app/loggers/database.clj +++ b/backend/src/app/loggers/database.clj @@ -62,7 +62,7 @@ (let [event (parse-event event) uri (cf/get :public-uri)] (l/debug :hint "registering error on database" :id (:id event) - :uri (str uri "/dbg/error-by-id/" (:id event))) + :uri (str uri "/dbg/error/" (:id event))) (persist-on-database! cfg event)) (catch Exception e (l/warn :hint "unexpected exception on database error logger" diff --git a/common/src/app/common/logging.cljc b/common/src/app/common/logging.cljc index f9356e588..b9940f1ea 100644 --- a/common/src/app/common/logging.cljc +++ b/common/src/app/common/logging.cljc @@ -65,7 +65,7 @@ val (coll? val) - (binding [clojure.pprint/*print-right-margin* 120] + (binding [clojure.pprint/*print-right-margin* 200] (-> (with-out-str (pprint val)) (simple-prune (* 1024 1024 3)))) @@ -83,6 +83,12 @@ (stringify-data val)]))) data))) +#?(:clj + (defn set-context! + [data] + (ThreadContext/putAll (data->context-map data)) + nil)) + #?(:clj (defmacro with-context [data & body] diff --git a/common/src/app/common/spec.cljc b/common/src/app/common/spec.cljc index b8fbd7986..19ef41255 100644 --- a/common/src/app/common/spec.cljc +++ b/common/src/app/common/spec.cljc @@ -256,7 +256,7 @@ (let [data (s/explain-data spec data)] (throw (ex/error :type :validation :code :spec-validation - :data data)))) + ::s/problems (::s/problems data))))) result)) (defmacro instrument!