This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-17
Channels
- # announcements (1)
- # babashka (21)
- # beginners (46)
- # calva (21)
- # cherry (10)
- # cider (5)
- # clojure (54)
- # clojure-europe (16)
- # clojure-nl (2)
- # clojure-norway (37)
- # clojure-spec (7)
- # clojure-uk (4)
- # clojurescript (30)
- # conjure (3)
- # cursive (1)
- # datalog (5)
- # datascript (3)
- # datomic (13)
- # emacs (5)
- # fulcro (82)
- # girouette (1)
- # helix (4)
- # hyperfiddle (2)
- # joyride (1)
- # juxt (1)
- # kaocha (4)
- # lambdaisland (3)
- # luminus (1)
- # malli (15)
- # off-topic (60)
- # pathom (3)
- # polylith (1)
- # practicalli (3)
- # releases (1)
- # ring (4)
- # sql (3)
- # squint (85)
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”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}
looks like it's discarding :int
, and then discarding the empty vector too? what happens if you change it to int?
?
sorry to not be more help, that's super weird
Version 0.8.4, in case anyone wants to see if they can reproduce it
can you share the full stack trace? maybe that will help
#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]]}
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
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
i bet this is it: https://github.com/metosin/malli/pull/690
seems likely
glad upgrading is the solution, that's a very easy solution lol