Skip to content
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

me/-resolve-root-error does not respect :error/path #554

Closed
tomasd opened this issue Oct 26, 2021 · 3 comments · Fixed by #589
Closed

me/-resolve-root-error does not respect :error/path #554

tomasd opened this issue Oct 26, 2021 · 3 comments · Fixed by #589
Labels
bug Something isn't working

Comments

@tomasd
Copy link
Contributor

tomasd commented Oct 26, 2021

If using validation functions and specifying :error/path, this is not taken into consideration when using me/-resolve-root-error:

(-> [:and [:map
           [:a :int]]
     [:fn {:error/path [:a]}
      (constantly false)]]
    (m/explain {:a 1})
    (me/humanize {:resolve me/-resolve-root-error}))
=> [nil]

It works with me/-resolve-direct-error:

(-> [:and [:map
           [:a :int]]
     [:fn {:error/path [:a]}
      (constantly false)]]
    (m/explain {:a 1})
    (me/humanize {:resolve me/-resolve-direct-error}))
=> {:a ["unknown error"]}
@tomasd
Copy link
Contributor Author

tomasd commented Oct 27, 2021

Here are failing test cases which should describe the problems with me/-resolve-direct-error:

  (is (= {:password2 ["passwords don't match"]}
        (-> [:and [:map
                   [:password string?]
                   [:password2 string?]]
             [:fn {:error/message "passwords don't match"
                   :error/path    [:password2]}
              '(fn [{:keys [password password2]}]
                 (= password password2))]]
            (m/explain {:password  "secret"
                        :password2 "faarao"})
            (me/humanize {:resolve me/-resolve-root-error}))))

  (is (= {:a ["failure"]}
         (-> [:map
              [:a {:error/message "failure"} [:enum "a" "b"]]]
             (m/explain {:a nil})
             (me/humanize {:resolve me/-resolve-root-error}))))

  (is (= {:a ["should be either a or b"]}
         (-> [:and [:map
                    [:a  [:enum "a" "b"]]]]
             (m/explain {:a nil})
             (me/humanize {:resolve me/-resolve-root-error}))))

@ikitommi ikitommi added the bug Something isn't working label Oct 30, 2021
@ikitommi
Copy link
Member

me/-resolve-root-error is a non-documented feature, but it's still a bug.

@tomasd
Copy link
Contributor Author

tomasd commented Dec 6, 2021

@ikitommi I did a PR fixing the above error, please have a look. I don't know if it's 100% correct as that part was quite hard to follow for me. The tests passed and it also works with even more hierarchical nestings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants