Skip to content

Conversation

@vkarpov15
Copy link
Collaborator

Summary

Stack traces for validate() are now fixed, and slightly better for save():

$ node gh-14250.js 
Save ValidationError: User validation failed: name: Validator failed for path `name` with value `A`
    at Document.invalidate (/home/v/Desktop/MongoDB/mongoose/lib/document.js:3327:32)
    at validatePath (/home/v/Desktop/MongoDB/mongoose/lib/document.js:3102:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 0)
    at async model.$__validate (/home/v/Desktop/MongoDB/mongoose/lib/document.js:3043:3)
    at async model.validate (/home/v/Desktop/MongoDB/mongoose/lib/document.js:2645:5)
    at async model.validateBeforeSave (/home/v/Desktop/MongoDB/mongoose/lib/plugins/validateBeforeSave.js:34:7) {
  errors: {
    name: ValidatorError: Validator failed for path `name` with value `A`
        at SchemaString.doValidate (/home/v/Desktop/MongoDB/mongoose/lib/schemaType.js:1392:13)
        at validatePath (/home/v/Desktop/MongoDB/mongoose/lib/document.js:3094:24)
        at model.$__validate (/home/v/Desktop/MongoDB/mongoose/lib/document.js:3040:21)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async model.validate (/home/v/Desktop/MongoDB/mongoose/lib/document.js:2645:5)
        at async model.validateBeforeSave (/home/v/Desktop/MongoDB/mongoose/lib/plugins/validateBeforeSave.js:34:7) {
      properties: [Object],
      kind: 'user defined',
      path: 'name',
      value: 'A',
      reason: undefined,
      [Symbol(mongoose#validatorError)]: true
    }
  },
  _message: 'User validation failed'
}

Still need more work for save().

Examples

@vkarpov15 vkarpov15 added this to the 9.0 milestone Mar 11, 2025
Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some questions to make sure.

@vkarpov15 vkarpov15 merged commit 1cb5ae4 into 9.0 Mar 12, 2025
76 checks passed
@hasezoey hasezoey deleted the vkarpov15/async-dovalidate branch March 12, 2025 19:31
@vkarpov15 vkarpov15 mentioned this pull request Mar 17, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants