SchemaType.validate does not allow a function to be used for a message if a custom type is not defined #8360
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Do you want to request a feature or report a bug?
bug
What is the current behavior?
SchemaType.validate
does not allow a function to be sent as a message if a custom type is not definedIf the current behavior is a bug, please provide the steps to reproduce.
So if I have the following for a custom schema type:
An error message won't be returned when validation fails.
Now If I define a custom type:
it works as expected.
I believe the error is caused at https://github.com/Automattic/mongoose/blob/master/lib/schematype.js#L679 (
if (message instanceof Object && !type)
) because apparently<function> instanceof Object
is true. I would imaginetypeof message === 'object'
would do in its placeWhat is the expected behavior?
The function should be called either way, not just if there is a custom type
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: 10.16.0
Mongoose: 5.7.11
MongoDB: 4.0.6
The text was updated successfully, but these errors were encountered: