TypeError: Cannot read property 'length' of undefined - when using .error()
See original GitHub issueWhen 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:
- Created 7 years ago
- Comments:7 (1 by maintainers)
Top 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 >
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 Free
Top 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
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
Closing, released 3.0