Closed ianjosephwilson closed 2 months ago
@ianjosephwilson There are a few ways you can do this, but first thing in my mind is something like:
def my_serializable_errs(invalid: Invalid) -> Serializable:
match invalid.err_type:
case PredicateErrs(preds):
return [
"whatever message" if isinstance(p, GreaterThan) else pred_to_err_message(p)
for p in preds
]
case _:
return to_serializable_errs(invalid, my_serializable_errs)
As noted in its docstring to_serializable_errs
is really meant more as an example implementation than anything. koda_validate attempts to be agnostic to error output -- whether it's serializable, text, or some other format. The reason for this is that generating error messages / data tends to vary widely between different applications -- different formats, languages (or multiple languages), etc.
I was trying out this library and I don't see a clear way to provide an error message for this custom predicate.