Skip to content

chore(model): use MongooseError instead of Error#16096

Merged
vkarpov15 merged 1 commit intoAutomattic:masterfrom
mahmoodhamdi:chore/issue-15995-standardize-errors-model
Mar 14, 2026
Merged

chore(model): use MongooseError instead of Error#16096
vkarpov15 merged 1 commit intoAutomattic:masterfrom
mahmoodhamdi:chore/issue-15995-standardize-errors-model

Conversation

@mahmoodhamdi
Copy link
Contributor

Summary

Replaces 6 instances of throw new Error(...) with throw new MongooseError(...) in lib/model.js as part of the effort to standardize error types across the codebase.

Changed locations:

  • useConnection() — missing connection argument
  • deleteOne() — pre hook argument overwrite
  • buildPreSavePromise() — pre save hook option overwrite in bulkSave
  • buildBulkWriteOperations() — invalid documents argument (2 instances)
  • clientEncryption() — missing ClientEncryption in driver

MongooseError extends Error, so this is fully backward-compatible.

Testing

All 777 model-related tests pass.

Re: #15995

Replace 6 instances of `throw new Error(...)` with
`throw new MongooseError(...)` in lib/model.js for consistency.

Re: Automattic#15995
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR standardizes several user-facing error throws in lib/model.js by using Mongoose’s base MongooseError class instead of the built-in Error, aligning with the broader codebase effort in #15995 to unify thrown error types.

Changes:

  • Replace throw new Error(...) with throw new MongooseError(...) in 6 call sites across model APIs and helpers.
  • Keep error messages unchanged while standardizing the error class used.

@vkarpov15 vkarpov15 merged commit bba2ec2 into Automattic:master Mar 14, 2026
30 checks passed
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