question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Errors as object instead of array

See original GitHub issue

Hey 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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

12reactions
jquensecommented, Sep 11, 2017

Not sure what you mean there… If you don’t know what you want what are you asking for?

1reaction
jquensecommented, Sep 11, 2017

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found