-
Notifications
You must be signed in to change notification settings - Fork 215
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
Humanize only includes one error #499
Labels
Comments
Doesn't look right. |
Does this look ok? (deftest robust-humanize-form
(let [f (fn [s] [:fn {:error/message s} (constantly false)])
=> ::irrelevant]
(are [schema value _ expected]
(is (= expected (-> (m/explain schema value) (me/humanize))))
;; simple cases
:any :any => nil
[:and :any :any] :any => nil
[:and (f "1") :any] :any => ["1"]
[:and (f "1") (f "1") :any] :any => ["1" "1"]
[:and (f "1") (f "2")] {:a :map} => ["1" "2"]
;; accumulate into maps if error shape is already a map
[:map [:x [:and [:map [:y :any]] seq?]]] 123 => ["invalid type"]
[:map [:x [:and [:map [:y :any]] seq?]]] {} => {:x ["missing required key"]}
[:map [:x [:and [:map [:y :any]] seq?]]] {:x 123} => {:x ["invalid type" "should be a seq"]}
[:map [:x [:and [:map [:y :any]] seq? (f "kosh")]]] {:x {}} => {:x {:y ["missing required key"]
:malli/error ["should be a seq" "kosh"]}}
[:map [:x [:and [:map [:y :any]] seq?]]] {:x {:y 123}} => {:x ["should be a seq"]}
;; don't derive error form from value in case of top-level error
[:map [:x [:and seq? [:map [:y :any]]]]] 123 => ["invalid type"]
[:map [:x [:and seq? [:map [:y :any]]]]] {} => {:x ["missing required key"]}
[:map [:x [:and seq? [:map [:y :any]]]]] {:x 123} => {:x ["should be a seq" "invalid type"]}
[:map [:x [:and seq? [:map [:y :any]]]]] {:x {}} => {:x ["should be a seq"]}
;; tuple sizes
[:map [:x [:tuple :int :int :int]]] {} => {:x ["missing required key"]}
[:map [:x [:tuple :int :int :int]]] {:x []} => {:x ["invalid tuple size 0, expected 3"]}
[:map [:x [:tuple :int :int :int]]] {:x [1 "2" 3]} => {:x [nil ["should be an integer"]]}
[:map [:x [:tuple :int :int :int]]] {:x [1 "2" "3"]} => {:x [nil ["should be an integer"] ["should be an integer"]]}
[:map [:x [:tuple :int [:and :int (f "fails")] :int]]] {:x [1 "2" "3"]} => {:x [nil ["should be an integer" "fails"] ["should be an integer"]]}
[:map [:x [:tuple :int :int :int]]] {:x [1 2 3]} => nil
;; sequences
[:and [:sequential :int] (f "1") (f "2")] [1 "2"] => [nil ["should be an integer"]]
[:and [:sequential :int] (f "1") (f "2")] [1 2] => ["1" "2"]))) |
Merged
Fixed in master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In some cases calling
malli.error/humanize
on multiple errors returns only one error message, even though it could return multiple. The behaviour changed after PR #333 was merged, but not to what I would expect.I wanted to use
humanize
to provide (structured) form validation output, but I need to show more than one error at a time when possible, so I think I have to make a workaround.The text was updated successfully, but these errors were encountered: