-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
-ref-schema
returns wrong path in -explainer
when the ref is a var
#1106
Comments
Here is a patch that fixes what I think the underlying error is, namely that the
|
me/humanize
fails on schemas with :ref
when using -resolve-root-error
-ref-schema
returns wrong path in -explainer
when the ref is a var
I'm not sure I have time to dig properly into this, but I did some investigation.
(def Referred [:map [:foo :int]])
(def Schema [:ref #'Referred])
(mu/subschemas Schema)
;; ==> [{:path [], :in [], :schema [:ref #'user/Referred]}
;; {:path [0 0], :in [], :schema [:map [:foo :int]]}
;; {:path [0 0 :foo], :in [:foo], :schema :int}] The same problem occurs with a non-var (me/humanize
(m/explain [:ref {:registry {::referred [:map [:foo :int]]}} ::referred] {:foo "2"})
{:resolve me/-resolve-root-error})
;; ==> :malli.core/invalid-schema
(:errors (m/explain [:ref {:registry {::referred [:map [:foo :int]]}} ::referred] {:foo "2"}))
;; ==> ({:path [0 :foo], :in [:foo], :schema :int, :value "2"})
(mu/subschemas [:ref {:registry {::referred [:map [:foo :int]]}} ::referred])
;; ==> [{:path [], :in [], :schema [:ref {:registry #:user{:referred [:map [:foo :int]]}} :user/referred]}
;; {:path [0 0], :in [], :schema [:map [:foo :int]]}
;; {:path [0 0 :foo], :in [:foo], :schema :int}] Could the fix be to always add the extra 0 to the path? Note how Line 1721 in 1749e03
I don't really understand why Line 1736 in 1749e03
Using (def Schema2 [:schema #'Referred])
(:errors (m/explain Schema2 {:foo "2"}))
;; ==> ({:path [0 0 :foo], :in [:foo], :schema :int, :value "2"})
(me/humanize
(m/explain Schema2 {:foo "2"})
{:resolve me/-resolve-root-error})
;; ==> {:foo ["should be an integer"]} |
What
I believe the
path
returned by the explainer of-ref-schema
is wrong when the ref is avar
. This originally turned up as follows:Using
malli.error/humanize
on a schema that uses:ref
to refer to another schema in avar
throws:malli.core/invalid-schema
.For example, the following will throw:
Analysis indicates that this is because the
path
passed to the resolver when using:ref
is too short: it receives[0 :foo]
, but(mu/get-in Schema [0 :foo])
isnil
. Thepath
should be[0 0 :foo]
, i.e. an extra leading0
to "deref" (?) the var of the reference:This causes the
schema
in thelet
-binding here to benil
, which in turn causes theproperties
call on the subsequent line to throwinvalid-schema
asnil
is not a valid schema.Steps to reproduce
Add the following test to
error_test.clj
:The text was updated successfully, but these errors were encountered: