Fork me on GitHub
#malli
<
2022-08-17
>
afleck14:08:41

is there an “exclusive or” way of combining schemas? say I have

(def foo-schema [:map [:id string?] [:foo number?]])
(def bar-schema [:map [:id string?] [:bar number?]])

(def foobar-schema [:orn [:foo foo-schema] [:bar bar-schema]])
if I do
(me/humanize (m/explain foobar-schema {:id :k :foo 3}))
I get
{:id ["should be a string" "should be a string"],
 :bar ["missing required key"]}
but ideally I only want to see a single :id ["should be a string"] error. I guess put more abstractly I’m wondering if there’s a way to know “minimal number of problems that if fixed would make the value valid”

afleck14:08:36

hmm seeming like maybe a multi schema could potentially be helpful

ikitommi16:08:40

:multi is good option here

Colin P. Hill19:08:41

Is this a bug, or am I misunderstanding something? :thinking_face: It looks like it's complaining about the :=> schema only having one child, when it clearly has two.

(defn test-fn
    {:malli/schema [:=>
                    [:cat :int]
                    [:int]]}
    [n]
    n)
=> #'user/test-fn
(require '[malli.dev :as dev])
=> nil
(dev/start!)
Execution error (ExceptionInfo) at malli.core/-fail! (core.cljc:136).
:malli.core/child-error {:type :=>, :properties nil, :children [[:cat]], :min 2, :max 2}

Noah Bogart20:08:02

looks like it's discarding :int , and then discarding the empty vector too? what happens if you change it to int??

Colin P. Hill20:08:57

Identical error

👍 1
Noah Bogart13:08:55

sorry to not be more help, that's super weird

Colin P. Hill13:08:09

Version 0.8.4, in case anyone wants to see if they can reproduce it

Noah Bogart13:08:53

can you share the full stack trace? maybe that will help

Colin P. Hill14:08:41

#error {
 :cause ":malli.core/child-error {:type :=>, :properties nil, :children [[:cat]], :min 2, :max 2}"
 :data {:type :malli.core/child-error, :message :malli.core/child-error, :data {:type :=>, :properties nil, :children [[:cat]], :min 2, :max 2}}
 :via
 [{:type clojure.lang.ExceptionInfo
   :message ":malli.core/child-error {:type :=>, :properties nil, :children [[:cat]], :min 2, :max 2}"
   :data {:type :malli.core/child-error, :message :malli.core/child-error, :data {:type :=>, :properties nil, :children [[:cat]], :min 2, :max 2}}
   :at [malli.core$_fail_BANG_ invokeStatic "core.cljc" 136]}]
 :trace
 [[malli.core$_fail_BANG_ invokeStatic "core.cljc" 136]
  [malli.core$_fail_BANG_ invoke "core.cljc" 134]
  [malli.core$_check_children_BANG_ invokeStatic "core.cljc" 162]
  [malli.core$_check_children_BANG_ invoke "core.cljc" 154]
  [malli.core$__EQ__GT$reify__7246 _into_schema "core.cljc" 1694]
  [malli.core$into_schema invokeStatic "core.cljc" 1921]
  [malli.core$into_schema invoke "core.cljc" 1912]
  [malli.core$schema invokeStatic "core.cljc" 1982]
  [malli.core$schema invoke "core.cljc" 1963]
  [malli.core$function_schema invokeStatic "core.cljc" 2390]
  [malli.core$function_schema invoke "core.cljc" 2387]
  [malli.core$function_schema invokeStatic "core.cljc" 2388]
  [malli.core$function_schema invoke "core.cljc" 2387]
  [malli.core$_register_function_schema_BANG_ invokeStatic "core.cljc" 2398]
  [malli.core$_register_function_schema_BANG_ invoke "core.cljc" 2395]
  [malli.core$_register_function_schema_BANG_ invokeStatic "core.cljc" 2396]
  [malli.core$_register_function_schema_BANG_ invoke "core.cljc" 2395]
  [malli.instrument$_collect_BANG_ invokeStatic "instrument.clj" 41]
  [malli.instrument$_collect_BANG_ invoke "instrument.clj" 39]
  [malli.instrument$collect_BANG_$fn__15014 invoke "instrument.clj" 70]
  [clojure.core.protocols$iter_reduce invokeStatic "protocols.clj" 49]
  [clojure.core.protocols$fn__8238 invokeStatic "protocols.clj" 75]
  [clojure.core.protocols$fn__8238 invoke "protocols.clj" 75]
  [clojure.core.protocols$fn__8178$G__8173__8191 invoke "protocols.clj" 13]
  [clojure.core$reduce invokeStatic "core.clj" 6886]
  [clojure.core$reduce invoke "core.clj" 6868]
  [malli.instrument$collect_BANG_ invokeStatic "instrument.clj" 70]
  [malli.instrument$collect_BANG_ invoke "instrument.clj" 58]
  [malli.dev$start_BANG_ invokeStatic "dev.clj" 23]
  [malli.dev$start_BANG_ invoke "dev.clj" 15]
  [malli.dev$start_BANG_ invokeStatic "dev.clj" 20]
  [malli.dev$start_BANG_ invoke "dev.clj" 15]
  [user$eval15353 invokeStatic "scratch_16.clj" 2]
  [user$eval15353 invoke "scratch_16.clj" 10]
  [clojure.lang.Compiler eval "Compiler.java" 7194]
  [clojure.lang.Compiler eval "Compiler.java" 7149]
  [clojure.core$eval invokeStatic "core.clj" 3215]
  [clojure.core$eval invoke "core.clj" 3211]
  [clojure.main$repl$read_eval_print__9206$fn__9209 invoke "main.clj" 437]
  [clojure.main$repl$read_eval_print__9206 invoke "main.clj" 437]
  [clojure.main$repl$fn__9215 invoke "main.clj" 458]
  [clojure.main$repl invokeStatic "main.clj" 458]
  [clojure.main$repl doInvoke "main.clj" 368]
  [clojure.lang.RestFn invoke "RestFn.java" 1523]
  [nrepl.middleware.interruptible_eval$evaluate invokeStatic "interruptible_eval.clj" 79]
  [nrepl.middleware.interruptible_eval$evaluate invoke "interruptible_eval.clj" 55]
  [nrepl.middleware.interruptible_eval$interruptible_eval$fn__10823$fn__10827 invoke "interruptible_eval.clj" 142]
  [clojure.lang.AFn run "AFn.java" 22]
  [nrepl.middleware.session$session_exec$main_loop__10925$fn__10929 invoke "session.clj" 171]
  [nrepl.middleware.session$session_exec$main_loop__10925 invoke "session.clj" 170]
  [clojure.lang.AFn run "AFn.java" 22]
  [java.lang.Thread run "Thread.java" 831]]}

👍 1
Colin P. Hill14:08:15

Issue disappears when I bump to version 0.8.9, which I don't see any reason not to do, so I suppose it's immaterial

Colin P. Hill14:08:09

Though I don't see anything about it in the change notes so maybe it was accidentally fixed and could still use a regression test, idk

Noah Bogart14:08:27

glad upgrading is the solution, that's a very easy solution lol