Fork me on GitHub

Add support for default/fallback branch for :map ( merged in master. Test/user reports welcome!


this is a nice bonus:

 [:map-of :int :int] 
 {1 1, 2 "2", "3" 3, "4" "4"} 
; => {1 1}


my colleague showed me some interesting behavior with decode. It has to do with what happens when a transformer throws. minimal example:

(mc/decode :sequential "32" (mtx/string-transformer))
It cropped up during a usage with an :or like this:
(mc/decode [:or :sequential :int] "32" (mtx/string-transformer))
Which you’d expect would return 32, but no. it throws:
clojure.lang.ExceptionInfo: :malli.core/child-error
{:type :malli.core/child-error, :message :malli.core/child-error, :data {:type :sequential, :properties nil, :children nil, :min 1, :max 1}}
 at malli.core$_exception.invokeStatic (core.cljc:138)
    malli.core$_exception.invoke (core.cljc:136)
It’s probably best if a transformer can never throw 1️⃣, but at least we need to handle exceptions in the parent schema 2️⃣ or both 3️⃣. Update: Just needed a child for the :sequential schema. the exception is getting thrown on schema creation.


I believe it's the schema creation: try (m/schema :sequential) , it requires 1 child, e.g (m/schema [:sequential :any]). m/decode coerces the data syntax into schema.


Good call, I should have read the error message more carefully.


heya, I’m trying to build a custom simple-schema using the example in the docs.

(def Between
    {:type `Between
     :compile (fn [_properties [min max] _options]
                (when-not (and (int? min) (int? max))
                  (malli/-fail! ::invalid-children {:min min, :max max}))
                {:pred #(and (int? %) (>= min % max))
                 :min 2 ;; at least 1 child
                 :max 2 ;; at most 1 child
                 :type-properties {:error/fn (fn [error _] (str "should be betweeb " min " and " max ", was " (:value error)))}})}))
However I get a “child error”, when I try to use it
(malli/form [Between 10 20])

   {:type :malli.core/child-error, :message :malli.core/child-error, :data {:type sqa.api-reitit.filter/Between, :properties nil, :children [10 20], :min 0, :max 0}}
It looks like malli.core/-simple-schema is not getting the correct min and max values - it expects :max and :min at the top level of the map passed to it - but I changed that and got some other errors using the schema so there may be some other things I’m missing


oh, I guess it's bad timing, this has just changed on master but unreleased

👍 2