Fork me on GitHub
#malli
<
2021-04-21
>
andrea.crotti12:04:45

I'm just trying malli for the first time today, and it looks pretty great already

andrea.crotti12:04:53

one thing I didn't quite understand though, if I annotate a function with (m/=> ... is there a way to actually force that check at runtime to make it fail when the schema doesn't match? I only see that related with generating a clj-kondo config, which is great but I thought that run-time assertions would be also there, even if disabled by default maybe

Setzer2212:04:10

Yes, I've been using my implementation for a couple of weeks now 👍 The base features are working, but sometimes malli has trouble generating human readable descriptions of errors

Setzer2212:04:37

if you give it a try, please report any issues!

andrea.crotti12:04:27

ah nice, yeah no rush was just wondering if I missed something from the docs

ikitommi12:04:22

@setzer22 yes, there is an open PR about robust humanized errors. Few combinations that don’t work, but the idea to fix it seems legit.

andrea.crotti13:04:43

another thing I noticed is that there isn't a way to just throw an exception if something fails to validate. I ended up with something like

(let [my-map ...
       errors (m/explain schema my-map)]
  (if (nil? errors) my-map (throw (ex-info "validation failed" errors)))
but isnt't there an easier way to do that?

nilern13:04:23

We should have an assert...

nilern13:04:05

There wasn't even an issue so I made one https://github.com/metosin/malli/issues/420

👍 3
nilern13:04:48

Hmm hard to make an efficient assert that makes the validator and explainer behind the scenes. Especially Cljs would be tricky.

andrea.crotti15:04:43

mm maybe you don't always need the explainer

andrea.crotti15:04:59

would be nice I guess but not sure it needs to be the default

nilern15:04:28

Dropping the explainer does not make it any easier.

yuhan17:04:06

Thanks for creating the issue! it must have slipped my mind. Do you mean caching a validator at the assert's compile time? I would be worried about the validator then going out of sync when you redefine the schema during dev time

yuhan17:04:44

Maybe the *assert* dynamic var could have 3 levels: • runtime validate (slowest but correct) • compile-time validator (more efficient, use if schemas are fixed) • compiles to nil

nilern13:04:18

Yeah I figured you just forgot. And I did mean the assert macro would create the validator

nilern13:04:02

It is probably ok to not do that in dev mode although sometimes assertion overhead is too much even then