diff --git a/CHANGELOG.md b/CHANGELOG.md index 872060d8d..30f4ba57d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Malli is in well matured [alpha](README.md#alpha). * Fix ClojureScript [arithmetic warning](https://github.com/metosin/malli/issues/1093) * Distribute `:merge` over `:multi` [#1086](https://github.com/metosin/malli/pull/1086), see [documentation](README.md#distributive-schemas) * allow `m/-proxy-schema` child to be a `delay` +* Fix `malli.dev.pretty` throws when explaining errors in nested maps [#1094](https://github.com/metosin/malli/issues/1096) ## 0.16.3 (2024-08-05) diff --git a/src/malli/error.cljc b/src/malli/error.cljc index 5310d7be6..fb4e40603 100644 --- a/src/malli/error.cljc +++ b/src/malli/error.cljc @@ -193,7 +193,7 @@ (reduce (fn [acc error] (cond-> acc (accept error) (-replace-in value (:in error) (wrap error) mask))) acc errors))) (defn -masked [mask x y] - (cond (map? x) (reduce-kv (fn [acc k v] (let [e (find y k)] (assoc acc k (if e (-masked mask v (val e)) mask)))) y x) + (cond (and (map? x) (or (nil? y) (map? y))) (reduce-kv (fn [acc k v] (let [e (find y k)] (assoc acc k (if e (-masked mask v (val e)) mask)))) y x) (set? x) (cond-> y (not= (count x) (count y)) (conj mask)) (sequential? x) (-fill y (count x) mask) :else y)) diff --git a/test/malli/error_test.cljc b/test/malli/error_test.cljc index d9b3335f5..bcd55480e 100644 --- a/test/malli/error_test.cljc +++ b/test/malli/error_test.cljc @@ -758,6 +758,11 @@ (for [error (:errors explain)] (me/error-value (assoc explain :errors [error]) {::me/mask-valid-values '...})))))) + (testing "masked nested maps #1096" + (is (= {"foo" "foo"} + (-> (m/explain [:map-of :keyword [:map-of :keyword :any]] {"foo" {:bar 1}}) + (me/error-value {::me/mask-valid-values '...}))))) + (testing "custom painting of errors" (is (= {:EXTRA {:value "KEY", :type :malli.core/extra-key} :tags #{{:value "ground"} {:value "coffee"}}