metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.44k stars 205 forks source link

decode errors out when transformer throws #876

Closed escherize closed 1 year ago

escherize commented 1 year ago

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 came up inside 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 with:

{: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)

I think to fix it we'd have to either:

ikitommi commented 1 year ago

It's not transformer, it's the schema creation (m/decode accepts both data and schema instances, in case of data, it call m/schema which fails here).

Try:

(m/schema :sequential)

Instead you should:

(m/schema [:sequential :any])
escherize commented 1 year ago

Thanks!