This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-14
Channels
- # adventofcode (36)
- # announcements (5)
- # atom-editor (2)
- # babashka (19)
- # beginners (98)
- # biff (7)
- # calva (25)
- # cider (1)
- # cljdoc (10)
- # clojure (70)
- # clojure-czech (1)
- # clojure-dev (14)
- # clojure-europe (79)
- # clojure-nl (1)
- # clojure-norway (8)
- # clojure-seattle (3)
- # clojure-uk (2)
- # clojurescript (28)
- # community-development (44)
- # core-typed (3)
- # cursive (2)
- # datalevin (5)
- # datascript (5)
- # datomic (1)
- # dev-tooling (12)
- # emacs (14)
- # honeysql (3)
- # humbleui (11)
- # introduce-yourself (1)
- # java (1)
- # kaocha (1)
- # lsp (3)
- # malli (21)
- # matcher-combinators (2)
- # nbb (7)
- # off-topic (15)
- # portal (12)
- # reitit (4)
- # releases (1)
- # shadow-cljs (59)
- # sql (8)
- # tree-sitter (3)
oh, that’s a bug. fixing it in https://github.com/metosin/malli/pull/798
still I have another pickle... so when I run explain-data, I can obtain all error messages into a sec. however, when I define :fn it doesnt put error as "last" as mentioned before, I will paste the real code, the gist of the problem is that map with :error/message is at different index of the vector
(def schema
[map
[:x [:fn #(= % 2) {:error/message "not 2"}]]
[:y [:string {:min 2 :error/message "longer than 2}]])
(def payload
{:x 3
:y "a"})
(->> (mu/explain-data schema payload)
:errors
(map #(-> % :schema last :error/message)))
not sure what you are doing, but:
(def schema
[:map
[:x [:fn {:error/message "not 2"} #(= % 2)]]
[:y [:string {:min 2 :error/message "longer than 2"}]]])
(def payload
{:x 3
:y "a"})
(->> (mu/explain-data schema payload)
:errors
(map #(-> % :schema m/properties :error/message)))
; => ("not 2" "longer than 2")
or you can use something like me/humanize
:
(->> (m/explain schema payload)
(me/humanize))
; => {:x ["not 2"], :y ["longer than 2"]}
great thanks... well I am trying to just aggregate error strings to push them as notifications... those examples work, thanks
I want to decode a string with an enum like so: [:enum :A :B] + "A" => :A
This doesn’t work:
(mc/decode [:enum :A :B] "A" (mtx/string-transformer))
;; => "A"
But all of these will work:
[(mc/decode [:and keyword? [:enum :A :B]] "A" (mtx/json-transformer))
(mc/decode [:and keyword? [:enum :A :B]] "A" (mtx/string-transformer))
(mc/decode [:enum {:decode/specific keyword} :A :B] "A" (mtx/transformer {:name :specific}))]
;;=> [:A :A :A]
Is there another (even better?) way to do that?not released, but https://github.com/metosin/malli/pull/782 last month 😎
(m/decode [:enum :A :B] "A" (mt/string-transformer))
;=> :A
sorry @UK0810AQ2, I can’t parse that.
@U055NJ5CC Oh, neato
will try to cut a release this year, need some work on the providers, a minor breaking change, so a minor
bump to 0.10.0
Is there an analogous function to prismatic schema’s check
? Here’s the docstring:
"Return nil if x matches schema; otherwise, returns a value that looks like the
'bad' parts of x with ValidationErrors at the leaves describing the failures.
If you will be checking many datums, it is much more efficient to create
a 'checker' once and call it on each of them."
I have this to work with:
{:schema [:map [:x int?]],
:value {:y "3"},
:errors ({:path [:x], :in [:x], :schema [:map [:x int?]], :value nil, :type :malli.core/missing-key})}
answering my own question here, using (me/humanize (m/errors $schema $value))
does similar thing to plumatic.schema/check
✨