Hey all, I've been running into an issue where I have some pretty big nested malli schemas. If I make too many changes at once, sometimes I will break the schema by adding some invalid syntax. However, the error message I get just says "invalid schema" (in cljs) with no further context. I started to work on a function that recursively walks through my entire schema and tests sub components for validity to try to pin down the issue. But this approach is a bit tricky because in malli subnodes in the schema datastructure may only be valid schemas when properly nested within another vector (like [:map [:key :int]]; [:key :int] is not a valid malli schema). I'm thinking that malli itself MUST have some functionality that can walk a schema like this, but I don't know where to find it. any tips?
I got AI to generate some monstrous code to do this that kinda works, but I would prefer to use something from malli itself if possible
The invalid-schema errors use ex-data to give you the invalid form, :y in this example.
user=> (m/schema [:map [:x :y]])
Execution error (ExceptionInfo) at malli.core/-exception (core.cljc:203).
:malli.core/invalid-schema
user=> *e
#error {
:cause ":malli.core/invalid-schema"
:data {:type :malli.core/invalid-schema, :message :malli.core/invalid-schema, :data {:schema :y, :form :y}}
:via
[{:type clojure.lang.ExceptionInfo
:message ":malli.core/invalid-schema"
:data {:type :malli.core/invalid-schema, :message :malli.core/invalid-schema, :data {:schema :y, :form :y}}
:at [malli.core$_exception invokeStatic "core.cljc" 203]}]
:trace
[[malli.core$_exception invokeStatic "core.cljc" 203]It's kind of a shame clojure repls (etc) don't print ex-data by default
I'll admit the user experience is not great, but at least that's better than just "invalid-schema"
The best solution (IMO) would be to have malli validate malli syntax: https://github.com/metosin/malli/issues/904
But we don't have that