mojotech / json-type-validation

TypeScript JSON type validation
MIT License
155 stars 14 forks source link

Simplify error messages related to unexpected data type #14

Closed mulias closed 6 years ago

mulias commented 6 years ago

Avoid including a stringified value in the error message, since it usually just repeats information already present in the input. In the worst case these bad errors can look like

{
  input: [{some: 1, ...}, {big: 2, ...}, {objects: 3, ...}, ...],
  at: "input",
  message: "expected a string, got [{some: 1, ...}, {big: 2, ...}, {objects: 3, ...}, ...]"
}

Since the full input is already provided, the signal to noise ratio is improved by changing the above error to

{
  input: [{some: 1, ...}, {big: 2, ...}, {objects: 3, ...}, ...],
  at: "input",
  message: "expected a string, got an array"
}