Fork me on GitHub
#malli
<
2021-04-07
>
armed13:04:07

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.]

armed13:04:32

What I'm missing here?

armed13:04:59

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')

ikitommi13:04:49

you could say [:maybe Schema2] and it should work.

ikitommi13:04:08

but, need to be fixed to be always robust.

armed13:04:00

@ikitommi thanks for explanation, going to use :maybe

danielneal15:04:58

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?

danielneal15:04:02

(malli.util/update
    (malli.core/schema
      [:map
       [:a {:optional true}
        int?]
       [:b {:optional true} int?]])
    :a identity)

danielneal15:04:09

;=> [:map [:a int?] [:b {:optional true} int?]]

nilern15:04:19

Looks like a bug to me :thinking_face:

danielneal15:04:51

Shall I open an issue?

nilern15:04:09

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

nilern15:04:00

I think an issue would at the very least be a better place to discuss how that should work

Hankstenberg20:04:30

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.

nilern20:04:39

Sounds like a more general version of strip-extra-keys-transformer