Hi all, I hope someone can help. I'm trying to figure out the best way to handle the validation errors for a function schema. For instance let's say for the sake of demo I have this
(m/=> get-resource [:=> [:cat [:map
[:id-secret [:map
[:type [:= :id-secret]]
[:id string?]
[:secret string?]]]]]
:any])
(defn get-resource
[opts]
(send opts))
and get-resource is part of a library consumed by different clients. The trouble is that when the input is invalid it throws an exception which includes the data as well and ideally it should be sanitised before returning the exception to the consumers? Is there any way that can be achieved without introducing breaking changes? Thank you.for instance calling it with (get-resource {:id-secret {:secret "some secret"}}) results in
#error {
:cause :malli.core/invalid-input
:data {:type :malli.core/invalid-input, :message :malli.core/invalid-input, :data {:input [:cat [:map [:id-secret [:map [:type [:= :id-secret]] [:id string?] [:secret string?]]]]], :args [{:id-secret {:secret some-secret}}], :schema [:=> [:cat [:map [:id-secret [:map [:type [:= :id-secret]] [:id string?] [:secret string?]]]]] :any]}}
:via
[{:type clojure.lang.ExceptionInfo
:message :malli.core/invalid-input
:data {:type :malli.core/invalid-input, :message :malli.core/invalid-input, :data {:input [:cat [:map [:id-secret [:map [:type [:= :id-secret]] [:id string?] [:secret string?]]]]], :args [{:id-secret {:secret some-secret}}], :schema [:=> [:cat [:map [:id-secret [:map [:type [:= :id-secret]] [:id string?] [:secret string?]]]]] :any]}}
:at [malli.core$_exception invokeStatic core.cljc 138]}]
:trace []
as you can see "some-secret" is included in the error which is not ideal as some consumers are logging the entire exception, if that makes senseHi Cris! I think at least you can use custom report function in m/instrument! like this:
(m/instrument! {:report (fn [type data]
(println "Error of type: " type))})thank you, I'll try that