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