This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-11
Channels
- # ai (1)
- # announcements (59)
- # aws (3)
- # babashka (16)
- # beginners (36)
- # calva (29)
- # cider (7)
- # clj-kondo (33)
- # clojure (77)
- # clojure-austin (1)
- # clojure-australia (4)
- # clojure-europe (16)
- # clojure-france (7)
- # clojure-nl (2)
- # clojure-spec (1)
- # clojure-sweden (8)
- # clojure-uk (4)
- # clojurescript (17)
- # cloverage (4)
- # conjure (2)
- # cursive (3)
- # datomic (22)
- # emacs (16)
- # fulcro (10)
- # graphql (3)
- # helix (13)
- # jobs (1)
- # kaocha (1)
- # lsp (7)
- # malli (1)
- # nextjournal (1)
- # off-topic (32)
- # pedestal (8)
- # polylith (5)
- # reitit (4)
- # reveal (1)
- # shadow-cljs (67)
- # spacemacs (7)
- # tools-deps (6)
- # xtdb (4)
Hi! I’m really into malli very recently. thanks! I have a question though. Here’s my example pants-schema.
(def pants-schema
[:and
[:map
[:id int?]
[:size {:optional true} [:maybe :int]]
[:size-alphabet {:optional true} [:maybe [:enum "S" "M" "L"]]]]
[:fn {:error/message "size and size alphabet should be nil-matched"}
'(fn [{:keys [size size-alphabet]}]
(or (and (nil? size) (nil? size-alphabet))
(and (some? size) (some? size-alphabet))))]])
You can see my nil-matched
fn schema. I’m trying to use the schema to validate for functions like below,
(defn do-something-with-pants
{:malli/schema [:=> [:cat pants-schema] :nil]}
[pants]
(prn pants)) ; do something
and then, if i pass the value {:id 1 :size 90}
into the do-something-with-pants
, I want to extract the error like humanize
results but I got the full error messages.
; Execution error (ExceptionInfo) at malli.core/-fail! (core.cljc:137).
; :malli.core/invalid-input {:input [:cat [:and [:map [:id int?] [:size [:maybe :int]] [:size-alphabet [:maybe [:enum "S" "M" "L"]]]] [:fn #:error{:message "size and size alphabet should be nil-matched"} (fn [{:keys [size size-alphabet]}] (or (and (nil? size) (nil? size-alphabet)) (and (some? size) (some? size-alphabet))))]]], :args [{:id 1, :size 90}], :schema [:=> [:cat [:and [:map [:id int?] [:size [:maybe :int]] [:size-alphabet [:maybe [:enum "S" "M" "L"]]]] [:fn #:error{:message "size and size alphabet should be nil-matched"} (fn [{:keys [size size-alphabet]}] (or (and (nil? size) (nil? size-alphabet)) (and (some? size) (some? size-alphabet))))]]] :nil]}
I know explain + humanize is very useful to see the readable results but as I feel like that’s good for development stage. In the web application, My needs are very important to me. How do I handle errors properly?