Errors as object instead of array
See original GitHub issueHey is there currently a way to get errors as an Object
keyed by the property names?
In other words:
const schema = yup.object().shape({
name: yup.string(),
age: yup.string().min(5),
})
schema.validate({ name: 'jimmy', msg: 'hi' })
.catch(function(err){
err.name // 'ValidationError'
err.errors // => {msg: 'msg must be at least 5 characters'} instead of ['msg must be at least 5 characters']
})
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Extremely annoying JavaScript array/object error
You can convert the arguments object into an array like this: var argsArray = Array.prototype.slice.call(arguments);.
Read more >Javascript error "The object is created as an array. Only ... - IBM
See exception for more details. Error: The object is created as an array. Only array functions are available. Object: TWObject[(Active: Y), ...
Read more >Is there a way to avoid array and object lookup runtime errors?
I'm wondering if there's a way to allow TypeScript to assume that the value is type undefined | number instead of incorrectly thinking...
Read more >Array. length Can Lead to Unexpected Errors
In JavaScript, arrays are not primitives but are instead objects. This means that the array's square bracket declaration probably works as a syntactical...
Read more >Resolving React Error, "Tried to merge an object, instead got ...
For instance, your state variable has initialized an empty object and you are trying to assign an array to it directly. This guide...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Not sure what you mean there… If you don’t know what you want what are you asking for?
sure! That’s why ValidationError has an
inner
property that contains all full error object for every error thrown.errors
is sort of a legacy property at this point