Fork me on GitHub
#malli
<
2024-05-13
>
dvingo18:05:02

In a clojure app using datomic I created the following malli schema:

(:import [datomic.db Db]))

(def DatomicDb (mc/-simple-schema {:type :datomic/db :pred (fn [v] (instance? Db v))}))
and that is working fine to validate a db instance. I have a problem when using this type in a function schema - when there is an instrumentation failure the entire database is being serialized/printed in the instrument error. Is there a way to override how the pretty printer prints a certain type?

dvingo18:05:53

oh, was pretty easy:

(:require [fipp.ednize :as ednize])
(extend-type datomic.db.Db
  ednize/IOverride
  ednize/IEdn
  (-edn [x] ""))

👏 1
Ben Sless19:05:16

You can also provide an error key to the schema

dvingo12:05:04

can you provide an example, adding the :error key to -simple-schema has no effect. The code path for the printer is (virhe/-visit) invoked here https://github.com/metosin/malli/blob/9f5b8095e1bc72b04ce8c006ae8951b73a0afcf9/src/malli/dev/pretty.cljc#L54 which calls fipp.visit/visit https://github.com/metosin/malli/blob/9f5b8095e1bc72b04ce8c006ae8951b73a0afcf9/src/malli/dev/virhe.cljc#L131 and I'm guessing it's hitting the unknown branch here: https://github.com/metosin/malli/blob/9f5b8095e1bc72b04ce8c006ae8951b73a0afcf9/src/malli/dev/virhe.cljc#L44 which calls the protocol fn fipp.ednize/-edn