Make error useful

This commit is contained in:
niten 2023-05-18 13:19:01 -07:00
parent f8c3bde04d
commit 3d6f69173b
1 changed files with 8 additions and 2 deletions

View File

@ -3,12 +3,16 @@
[milquetoast.client :as mqtt]
[clojure.core.async :refer [go-loop <!]]
[fudo-clojure.logging :as log]
[clojure.pprint :refer [pprint]]
[malli.core :as t]
[malli.error :refer [humanize]]))
(defn- sized-string [min max]
(t/schema [:string {:min min :max max}]))
(defn- pprint-to-string [str]
(with-out-str (pprint str)))
(def Notification
(t/schema [:map
[:summary (sized-string 1 80)]
@ -27,7 +31,9 @@
:body (:body note)
:urgency (-> note :urgency (keyword))
})
(log/error! logger (format "rejecting invalid notification: %s"
(humanize (t/explain Notification note)))))
(let [err (humanize (t/explain Notification note))]
(log/error! logger (format "rejecting invalid notification: %s (%s)\n%s"
(:summary err) (:body err)
(pprint-to-string note)))))
(recur (<! note-chan)))
(log/info! logger "stopping")))))