Created
September 5, 2025 16:35
-
-
Save escherize/c77d9d6ca02775c5bbb2d7ff382b0158 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Unstaged | |
| modified src/metabase/lib/metadata/calculation.cljc | |
| @@ -22,7 +22,8 @@ | |
| [metabase.util.i18n :as i18n] | |
| [metabase.util.log :as log] | |
| [metabase.util.malli :as mu] | |
| - [metabase.util.malli.registry :as mr])) | |
| + [metabase.util.malli.registry :as mr] | |
| + [malli.error :as me])) | |
| (mr/def ::display-name-style | |
| "Schema for valid values of `display-name-style` as passed to [[display-name-method]]. | |
| @@ -475,6 +476,39 @@ | |
| (or | |
| (empty? columns) | |
| (apply distinct? (map :lib/desired-column-alias columns))))]]) | |
| +#_:clj-kondo/ignore ;;nocommit | |
| +(require '[malli.core :as mc] '[malli.error :as me] '[malli.util :as mut] '[metabase.util.malli :as mu] | |
| + '[metabase.util.malli.describe :as umd] '[malli.provider :as mp] '[malli.generator :as mg] | |
| + '[malli.transform :as mtx] '[metabase.util.malli.registry :as mr] '[malli.json-schema :as mjs] | |
| + '[metabase.util.malli.humanize :as mu.humanize]) | |
| + | |
| +;; # without friendly locale: | |
| +(mu.humanize/humanize | |
| + (mr/explain [:int {:error/message {:en "Error code XYZ73" | |
| + :friendly "Hey friend, you gave me bad"}}] | |
| + "3")) | |
| +;; => "Error code XYZ73" | |
| + | |
| +(mu.humanize/humanize | |
| + (mr/explain [:int {:error/fn {:en (fn [{:keys [value]} _] (str "Error code XYZ73: " value)) | |
| + :friendly (fn [{:keys [value]} _] (str "Hey friend, you gave me " value))}}] | |
| + "3")) | |
| +;; => "Error code XYZ73: 3" | |
| + | |
| +;; # with friendly locale: | |
| +(mu.humanize/humanize | |
| + (mr/explain [:int {:error/message {:en "Error code XYZ73" | |
| + :friendly "Hey friend, you gave me bad"}}] | |
| + "3") | |
| + {:locale :friendly}) | |
| +;; => "Hey friend, you gave me bad" | |
| + | |
| +(mu.humanize/humanize | |
| + (mr/explain [:int {:error/fn {:en (fn [{:keys [value]} _] (str "Error code XYZ73: " value)) | |
| + :friendly (fn [{:keys [value]} _] (str "Hey friend, you gave me " value))}}] | |
| + "3") | |
| + {:locale :friendly}) | |
| +;; => "Hey friend, you gave me 3" | |
| (mr/def ::returned-columns.options | |
| "Schema for options passed to [[returned-columns]] and [[returned-columns-method]]." | |
| modified src/metabase/util/malli/humanize.cljc | |
| @@ -4,8 +4,8 @@ | |
| (defn- resolve-error | |
| "This is the same behavior as what [[malli.error/humanize]] does to resolve errors." | |
| - [explanation error] | |
| - (me/-resolve-direct-error explanation error {:wrap :message, :resolve me/-resolve-direct-error})) | |
| + [explanation error options] | |
| + (me/-resolve-direct-error explanation error (merge {:wrap :message, :resolve me/-resolve-direct-error} options))) | |
| (defn- flatten-error | |
| "Given a `[path message]` pair like | |
| @@ -61,11 +61,12 @@ | |
| combines 'resolved' errors in a different way that avoids discarding errors in `:or` schemas when they occur at | |
| different levels of nesting (see [[metabase.util.malli.humanize-test/basic-test]] | |
| or [[metabase.util.malli.humanize-test/basic-test-2]] for example) and eliminates duplicates." | |
| - [{:keys [errors], :as explanation}] | |
| - (transduce | |
| - (comp (map (fn [error] | |
| - (resolve-error explanation error))) | |
| - (map flatten-error)) | |
| - (completing merge-errors) | |
| - nil | |
| - errors)) | |
| + ([explanation] (humanize explanation {})) | |
| + ([{:keys [errors], :as explanation} options] | |
| + (transduce | |
| + (comp (map (fn [error] | |
| + (resolve-error explanation error options))) | |
| + (map flatten-error)) | |
| + (completing merge-errors) | |
| + nil | |
| + errors))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment