Hey, have issue with malli.error/humanize
, here is minimal example (cljs):
(let [Schema2 [:map
[:field keyword?]]
Schema [:map
[:foo int?]
[:bar [:or nil? Schema2]]]]
(malli.error/humanize
(malli/explain Schema {:foo 1
:bar {:field "test"}})))
Throws error: #object[Error Error: Vector's key for assoc must be a number.]
What I'm missing here?
By the way, in clojure I get another error for same snippet:
Execution error (ClassCastException) at malli.error/-ensure (error.cljc:124).
class clojure.lang.Keyword cannot be cast to class java.lang.Number (clojure.lang.Keyword is in unnamed module of loader 'app'; java.lang.Number is in module java.base of loader 'bootstrap')
@armed itโs a known issue, see https://github.com/metosin/malli/pull/333
you could say [:maybe Schema2]
and it should work.
but, need to be fixed to be always robust.
@ikitommi thanks for explanation, going to use :maybe
When I call malli.util/update
on a schema, the properties of the key I update are dropped, is there any way to preserve them?
(malli.util/update
(malli.core/schema
[:map
[:a {:optional true}
int?]
[:b {:optional true} int?]])
:a identity)
;=> [:map [:a int?] [:b {:optional true} int?]]
Looks like a bug to me :thinking_face:
Shall I open an issue?
:thinking-face: util/update
is implemented by getting the value, then setting it
But it would be reasonable to expect that update
preserves the properties even if get
+ assoc
would not
I agree
I think an issue would at the very least be a better place to discuss how that should work
cool, added one here https://github.com/metosin/malli/issues/412
What would be a good way to "cut" a data structure using a schema that it partially adheres to? To keep what conforms to the schema and discard the rest? The best approach I can think of is to use m/explain and then use the data from :errors to run an update-in on the data. Is there a better way to do that? It seems to me like there should be.
Sounds like a more general version of strip-extra-keys-transformer
Or perhaps the tentative coercer
https://github.com/metosin/malli/issues/404