Is there a way to get better guardrails messages, I have this config:
{:expound {:show-valid-values? true
:print-specs? true}
:guardrails/compact? false
:guardrails/stack-trace :prune
}
but I am using malli.Here’s an example of message that doesn’t tell me much:
Guardrails:
-- Validation Error com.fulcrologic.guardrails.malli.core:117 --
Value:
nil
Errors:
[“should be a keyword”]
Schema:
:keyword
More information:
https://cljdoc.org/d/metosin/malli/CURRENT
------------------------------------------------------------
Pruned Stack Trace (see gr.utils/last-failure-stacktrace for full trace)
[“roklenarcic.edavki.trade$eval15455$open_close__15456.invoke” “trade.clj” 28] called by [“roklenarcic.edavki.trade$eval15469$merge_stats__15470.invoke” “trade.clj” 35] called by [“roklenarcic.edavki.trade_test$fn__18273.invokeStatic” “trade_test.clj” 46] called by [“roklenarcic.edavki.trade_test/fn” “trade_test.clj” 43] called by [“cognitect.test_runner$test.invokeStatic” “test_runner.clj” 74]
in this case it was return spec that failed but that’s not clear from the text
Another issue is that when I have a vector of maps, if there’s a spec failure it shows me the wrong value, but not any siblings in map so when the vector has 500 maps with 20 props each it is hard to find out which one is wrong. E.g.:
Guardrails:
-- Validation Error com.fulcrologic.guardrails.malli.core:117 --
Value:
[[... {:roklenarcic.edavki.security/sym 1}]]
Errors:
[[nil
{:roklenarcic.edavki.security/sym ["should be a string"
"should be a string"]}]]
Schema:
[:sequential :roklenarcic.edavki.trade/lot]
Here if I could see the rest of the map I would be able to see the :id key and I would be able to find the offending data instantly.isn’t that telling you that the sym key should be a sequence of lot, which I guess are strings?
it’s filtering OUT the stuff that passed
oh, I see…you’re saying that there is an item in the collection, and you’d like to know which one
Sure the rest of the keys passed, but it’s kinda hard to know which item has this property, unless I boot the debugger and find the one that has sym 1
The schema messages are generated by malli. Talk to them 😄
I’m open to PRs in GR that improve whatever you want…but tap> is there so you could use Portal or something to see the failing value that way
the general problem is quite hard: How do I make a generic tool that gets any possible data of any format in the world, and tells you what is wrong with that (arbitrarily large) data?
you want the :id, someone else wants the vector offset, someone else wants a java object turned into a map via bean, etc.
yeah I understand
almost no one wants a vector of 500 itesm with 20 keys each 😄
does the value go into tap?
Honestly I don’t remember where tap is used. I didn’t write that part of GR…I just know it is there
check out the source
doesn’t seem to be the case, I tried add-tap println and nothing gets printed when calling function with wrong argument types
? I don’t understand. It’s a GR config option
you tell GR that you want to tap
see docs
Ok, thanks