Fork me on GitHub
#malli
<
2023-02-23
>
steveb8n19:02:19

Q: I’m using instrumented fns and they are logging invalid data correctly but I’m drowning in logs from this in some cases. Is there a way to make an invalid fn input throw an exception i.e. halt on first bad value detected instead of continuing?

steveb8n19:02:55

Hmm, I see the default report behaviour is m/-fail so it must be my code. I’m using core.async with the go-try macro from org.clojars.akiel/async-error

steveb8n19:02:37

maybe it’s go-try that is continuing processing when Malli has thrown?

escherize19:02:14

Are you using mx/defn?

steveb8n19:02:36

nope: using m/=>

steveb8n19:02:18

but I’m not using a global/default registry so that’s a bit different to the way the docs show it

steveb8n19:02:48

I have a custom registry which I provide to the m/=> form

escherize19:02:05

And you need it to just throw when an error occurs instead of log?

steveb8n19:02:07

(btw hi Brian. it’s been a while 🙂

steveb8n19:02:25

yes, exactly

escherize19:02:27

Hey Steve 🙂

steveb8n19:02:50

oh cool. I’ll try that

escherize19:02:52

heres the one we are using. explain-fn-fail! throws

escherize19:02:06

but any reporter that throws should solve it

escherize19:02:19

It’s been a while!

steveb8n19:02:17

oh, I found my mistake. I was using pretty/reporter when I should have been using pretty/thrower

👍 2
steveb8n19:02:39

thanks anyway for the nudge. that helped me find the best option

🆒 2
Brett Rowberry21:02:23

No rush. I was wondering if there’s a release planned that includes the fixes for https://github.com/metosin/malli/issues/819

ikitommi09:02:54

Will cut a release next week

gratitude-thank-you 2
Jakub Šťastný23:02:29

Hey guys. I'm looking at the screenshot in the README (https://raw.githubusercontent.com/metosin/malli/master/docs/img/malli-defn.png) and it's precisely what I'm trying to achieve. I have this: (m/=> qid-str [:=> [:cat :int] :int]) (defn qid-str [version-number-list] (str/join "." version-number-list)) (qid-str [1 2 3 4]) But it's not doing anything. How do I hook up the schema validation into the fn execution, just like it's in the screenshot?

escherize04:02:01

did you call (dev/start)?

escherize04:02:24

You could also look into using mx/defn

escherize04:02:40

also I think it’s: (m/=> qid-str [:=> [:cat [:sequential :int]] :int])

Jakub Šťastný14:02:38

Where does (dev/start) come from?

Jakub Šťastný14:02:54

That sounds like some HTTP thing. I just have a very simple CLI app.

camdez14:02:58

Hey Jakub. I just went through this earlier in the week and it was rather confusing for me (but I got there!). Here’s what I (and perhaps you) need(ed) to know: 1. malli.instrument/collect! needs to be called to find all of the function annotations in the namespaces you tell it, or the current namespace by default. 2. malli.instrument/instrument! then rewrites the functions to include the validation you’re looking for. 3. ! will do both of these things for you. 4. It also installs a watcher that will do that rewriting process automatically when m/=> is evaluated. 5. Contrary to the docs, the order of the function and the m/=> matters (a lot) for this case. If you eval the m/=> first, and then the function (as will happen in your code), the function will be redefined without the validation.

Jakub Šťastný14:02:14

@U0CV48L87 thanks Cameron, that's very helpful.

camdez14:02:12

Happy to help. Let me know if that gets it working for you.

👍 2
camdez14:02:21

One more gotcha to watch out for: if namespaces aren’t loaded (yet) then they’re not going to get instrumented. It’s less of a problem when using , since you can work around it using m/=>, it can be a headache in tests or if you’re trying to use the function metadata annotations. I haven’t gotten to a setup I’m entirely happy with for both interactive development and testing.

camdez14:02:15

Using the macro annotation form should solve all of the issues, but I was hesitate to adopt it first.

Jakub Šťastný14:02:28

Good to know. It's a lot to digest (as I'm generally fairly new to Clojure, though not to programming). Malli does look great.

Jakub Šťastný14:02:40

Oh wow good note on the namespaces!

escherize18:02:07

> Where does (dev/start) come from? It is the requires in the screenshot you posted.