I'd like decoder errors to be able to work with custom validation errors. Many of my types follow the "always valid" pattern, where types cannot be constructed without valid data.
As an example, given the following JSON, which has some type and value issues:
{
"number": "a",
"audit": {
"createdBy": null,
"date": "2021-07-66"
}
}
I would like to generate some errors like the following:
[
{ field = "number"; message = "The value 'a' was not a valid number" }
{ field = "audit.createdBy"; message = "The field 'createdBy' is required" }
{ field = "audit.date"; message = "The value '2021-07-66' was not a valid date" }
]
However, it does not appear to be possible, I cannot access a hierarchy of errors form a Decoder Error. The type seems to represent only a single error. The signature is as follows:
type DecoderError = string * ErrorReason
I was expecting the Decoder Error to be a Generic Data Structure which would be able to represent arbitrary errors passed up from a decoder all the fields, something like:
type DecoderError = DecoderItemError[]
type DecoderItemError = field: string * reason: ErrorReason * children: DecoderItemError[]
Is it possible to do something like this with Thoth? Or is the error always a string?
The docs point to this as an example of a decoder error:
Error at: `$.user.firstname`
Expecting an object with path `user.firstname` but instead got:
{
"user": {
"name": "maxime",
"age": 25
}
}
Node `firstname` is unknown.
I'm looking for an approach to achieve these validation errors using Thoth, thanks.
I'd like decoder errors to be able to work with custom validation errors. Many of my types follow the "always valid" pattern, where types cannot be constructed without valid data.
As an example, given the following JSON, which has some type and value issues:
{ "number": "a", "audit": { "createdBy": null, "date": "2021-07-66" } }I would like to generate some errors like the following:
However, it does not appear to be possible, I cannot access a hierarchy of errors form a Decoder Error. The type seems to represent only a single error. The signature is as follows:
type DecoderError = string * ErrorReasonI was expecting the Decoder Error to be a Generic Data Structure which would be able to represent arbitrary errors passed up from a decoder all the fields, something like:
Is it possible to do something like this with Thoth? Or is the error always a string?
The docs point to this as an example of a decoder error:
I'm looking for an approach to achieve these validation errors using Thoth, thanks.