This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-30
Channels
- # announcements (1)
- # asami (60)
- # babashka (7)
- # beginners (19)
- # biff (5)
- # calva (12)
- # cherry (4)
- # cider (8)
- # clerk (3)
- # clojure-europe (3)
- # clojuredesign-podcast (2)
- # clojurescript (8)
- # data-science (48)
- # fulcro (8)
- # hyperfiddle (21)
- # leiningen (1)
- # malli (7)
- # music (3)
- # off-topic (7)
- # pedestal (15)
- # portal (8)
- # releases (2)
Hi 🙂 Given the schema:
[:schema
{:registry
{"hiccup" [:orn
[:kindly [:fn {:error/message "should have kindly metadata"} kind]]
[:primitive [:or string? number? boolean? nil?]]
[:fragment [:or
[:and seq?
[:catn [:children [:* [:schema [:ref "hiccup"]]]]]]
[:and vector?
[:catn [:fragment-indicator [:= :<>]]
[:children [:* [:schema [:ref "hiccup"]]]]]]]]
[:tag-node [:and vector?
[:catn [:tag simple-keyword?]
[:attrs [:? [:and [:not [:fn kind]]
[:schema [:ref "attrs"]]]]]
[:children [:* [:schema [:ref "hiccup"]]]]]]]
[:raw-node [:and vector?
[:catn [:raw-indicator [:= :hiccup/raw-html]]
[:content string?]]]]
[:component-node [:and vector?
[:catn [:view-fn [:and fn?
[:function [:=> [:cat any?]
[:schema [:ref "hiccup"]]]]]]
[:children [:* any?]]]]]
[:reagent-node [:and vector?
[:catn [:component [:or [:and list? [:cat [:= 'fn]]]
symbol?]]
[:args [:* any?]]]]]
[:scittle-node [:and vector?
[:catn [:forms [:+ list?]]]]]]
;; TODO: attrs may be over restricted (why not accept anything string-able?) and under specified (only styles can be maps)
"attrs" [:map-of
[:or string? keyword? symbol?]
[:or string? keyword? symbol? number? boolean? nil? vector?
[:schema [:ref "attrs"]]]]}}
"hiccup"]
Trying to explain a very basic failure:
(html [:div [:h2 "hi"] '(info)])
me/humanize returns:
["should have kindly metadata" "should be a string" "should be a number" "should be a boolean" "should be nil" "should be a seq"]
Which doesn't point to the actual error: '(info) is not valid hiccup.
Any suggestions for how to get a more informative error message in this scenario?you can call malli.error/with-error-messages
on the explain result to access all information. Does that help?
but, for sequence schemas, the errors are not always very nice, might report on (intuitively) wrong branch on :alt|n
.
but, if the explain (with error messages) has all the info you see important here, you can plug custom resolver via :resolve
option to reduce the most relevant error.
also, suggestions to make the default error resolving in humanize
better most welcome!
with-error-messages
creates something so long I can't paste it in this chat 😞
What I'd like to see is either something like this:
[:div [:h2 "hi"] *ERROR]*
or
[:div [:h2 "hi"] '(info)]
^ERROR
because the outer div
and inner h2
are fine, it is just the form at the end that is bad.
Maybe this is very difficult because the grammar might say oh but the entire expression is not hiccup because of the error. From a human point of view, the outer expression is fine, but because there is an error at the tail position, it invalidate the entire expression. I don't know how to create a (recursive) grammar that can eagerly accept that some parts are correct, only a small part is incorrect.
One idea that comes to mind is that I could allow '(info)
to be considered correct in the grammar (match any?
) and then handle that clause as an error in my code. That solves the problem for coding, but then the grammar is no longer useful for sharing as a standard.
Have you ever encountered such a situation?