fast-json-stringify
fast-json-stringify copied to clipboard
feat: add validationErrors to schema mismatch errors
when using a schema that includes anyOf or oneOf and it fails to find a match the error is pretty worthless (in my case it is usually 'The value of \'#\' does not match schema definition.')
and it is not trivial to debug since stack trace points to anonymous functions composed at runtime.
this sets the validation errors on the error before throwing it. if the performance penalty is too big I suggest it should be behind a verbose option
CC @mcollina @ivan-tymoshenko
I like the idea, but I don't uunderstand the purpose of accumulating errors. Why we can't throw them if validation fails without accumulating?
with anyOf or oneOf we go over all the possible schemas and if validation passes we use that schema for serialization. for the case where non of the possibilities matches - each of the errors is relevant I think
Oh, I see. Can you modify the validate function to also return errors when validation fails and put the error acumulation directly into anyof/oneOf block please? Reseting errors globaly might be a problem for some cases in the future.
@ivan-tymoshenko @mcollina is there anything else missing to get this merged?