MakeTypes icon indicating copy to clipboard operation
MakeTypes copied to clipboard

Better error messages when runtime type checking fails

Open jvilk opened this issue 8 years ago • 1 comments

What's a good way to have decent error messages without adding too much overhead / context tracking embedded in the JSON objects?

jvilk avatar Dec 18 '16 23:12 jvilk

If you would emit json-schemas, then one could use ajv for runtime error reporting. I like it because then I can use the same schema to (A) validate strictly (throw errors etc, like MakeTypes does), or (B) ensure valid type by assigning defaults to required fields and using type coercion. Usually one needs to filter additional properties with removeAdditional, but sometimes APIs use objects as hashes where index types are needed. In that case it is good to filter out Object.prototype properties at least so that the resulting objects are well-behaving in runtime. So there could be all kinds of intricacies to get json-schemas work, but it might be worth it.

plievone avatar Feb 10 '17 10:02 plievone