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.

TypeError: Cannot read property 'length' of undefined - when using .error()

See original GitHub issue

When trying to set a custom error message as per Joi API reference, for example: Joi.string().error(new Error('expected a string, actually')) then express-validation throws TypeError: Cannot read property 'length' of undefined in index.js line 76 because .error(new Error('message')) produces an Error instance without .details or other decorations of the ValidationError so errors.details.length cannot be accessed directly as errors.details is undefined.

Should another route be chosen to allow for custom error messages (especially important for regexes) or should the condition be improved to distinguish between ValidationErrors and generic Errors?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
colthreepvcommented, Mar 16, 2017

Sure, I see your point, probably will go with that (1), the custom branch should be a little more solid now.

I will see how that merges in the 2.x branch, will release it also for 1.x version to avoid application crashes

0reactions
AndrewKeigcommented, Mar 6, 2020

Closing, released 3.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read properties of undefined (reading 'length') - TrackJS
This message indicates that our code expects to have an object with a length property, but that object was not present. length is...
Read more >
Typeerror: Cannot Read Property 'length' of Undefined
A typeerror length of undefined can indicate that the actual type of an operand is different from the expected type. This error can...
Read more >
ERROR TypeError: Cannot read property 'length' of undefined
I got stuck in a similar situation where even after assigning results as an array ( as shown below ), the error persisted....
Read more >
[SOLVED] Cannot Read Property 'length' of Undefined in JS
To fix the “cannot read property 'length' of undefined” error, perform an undefined check on the variable before accessing the length property ......
Read more >
Cannot read properties of undefined (reading 'length') in JS
The "TypeError: Cannot read properties of undefined (reading 'length')" error occurs when accessing the length property on an undefined value. To solve the ......
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