Improve error reporting of tasks.

This commit is contained in:
Andrey Antukh 2021-02-03 17:00:35 +01:00 committed by Hirunatan
parent 816db29f9c
commit 80309cbff3
5 changed files with 50 additions and 27 deletions

View file

@ -12,6 +12,7 @@
(:require
[app.common.uuid :as uuid]
[app.config :as cfg]
[app.util.log4j :refer [update-thread-context!]]
[clojure.pprint :refer [pprint]]
[clojure.tools.logging :as log]
[cuerdas.core :as str]
@ -19,19 +20,6 @@
(:import
org.apache.logging.log4j.ThreadContext))
(defn update-thread-context!
[data]
(run! (fn [[key val]]
(ThreadContext/put
(name key)
(cond
(coll? val)
(binding [clojure.pprint/*print-right-margin* 120]
(with-out-str (pprint val)))
(instance? clojure.lang.Named val) (name val)
:else (str val))))
data))
(defn- explain-error
[error]
(with-out-str
@ -48,10 +36,8 @@
:version (:full cfg/version)
:host (:public-uri cfg/config)
:class (.getCanonicalName ^java.lang.Class (class error))
:hint (ex-message error)}
(when (map? edata)
edata)
:hint (ex-message error)
:data edata}
(when (and (map? edata) (:data edata))
{:explain (explain-error edata)}))))