This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-24
Channels
- # announcements (39)
- # aws (4)
- # babashka (18)
- # beginners (32)
- # biff (10)
- # calva (22)
- # clj-kondo (11)
- # clj-on-windows (2)
- # cljs-dev (20)
- # clojure (31)
- # clojure-europe (130)
- # clojure-norway (21)
- # clojure-spec (24)
- # clojure-uk (17)
- # clojured (2)
- # clojurescript (6)
- # conjure (1)
- # core-async (5)
- # cursive (11)
- # datalevin (1)
- # datomic (9)
- # emacs (24)
- # figwheel-main (42)
- # fulcro (6)
- # gratitude (6)
- # honeysql (8)
- # juxt (16)
- # kaocha (6)
- # lsp (235)
- # malli (2)
- # nbb (7)
- # off-topic (23)
- # other-languages (24)
- # pedestal (7)
- # reitit (6)
- # sci (1)
- # shadow-cljs (21)
- # tools-build (22)
- # tools-deps (57)
- # vim (24)
hello folks, I am starting to use reitit with malli I am currently looking into a way to have the coercion run, but instead of breaking in case something is off, to report it. so we were doing something like this:
(defn- safe-coercer [coercion-type original-coercer]
(fn [value format]
(let [result (original-coercer value format)]
(if (coercion/error? result)
(do (log/errorf (str coercion-type " coercion failed with data %s")
(into {} result))
value)
result))))
(defn- create-safe-coercion [original-coercion]
^{:type ::coercion/coercion}
(reify coercion/Coercion
(-get-name [_this]
(coercion/-get-name original-coercion))
(-get-options [_this]
(coercion/-get-options original-coercion))
(-get-apidocs [_this specification data]
(coercion/-get-apidocs original-coercion specification data))
(-compile-model [_this model name]
(coercion/-compile-model original-coercion model name))
(-open-model [_this model] (coercion/-open-model original-coercion model))
(-encode-error [_this error] (coercion/-encode-error original-coercion error))
(-request-coercer [_this type model]
(safe-coercer "request" (coercion/-request-coercer original-coercion type model)))
(-response-coercer [_this model]
(safe-coercer "response" (coercion/-response-coercer original-coercion model)))))
(def coercion-safe
(create-safe-coercion
(reitit.coercion.malli/create
(assoc-in reitit.coercion.malli/default-options [:transformers :body :default]
reitit.coercion.malli/string-transformer-provider))))
so… it runs OK in dev time, but it breaks when generating the uberjar: it says that -request-coercer
is not being implemented…
any clues? a better way to achieve the same result?
you could add an exception handler middleware / interceptor and handle stuff there. I think you have everything in the ex-data
@U5B8QSSC9 AOT is a beast, you might end up having protocol instances and definitions compiled with different ClassLoaders(?), so they don’t work together. In your case, the coercion-safe
is mostly likely AOT-compiled. 2 good options:
1. AOT-compile as little as possible, e.g. a separate minimal main where you do a requiring-resolve
for the actual code -> dynamic linking, slower startup, just works
2. make the coercion-safe
a defn
, so the instance is not AOT-compiled, just a function to generate it