chore(model): use MongooseError instead of Error#16096
Merged
vkarpov15 merged 1 commit intoAutomattic:masterfrom Mar 14, 2026
Merged
Conversation
Replace 6 instances of `throw new Error(...)` with `throw new MongooseError(...)` in lib/model.js for consistency. Re: Automattic#15995
Contributor
There was a problem hiding this comment.
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(...)withthrow new MongooseError(...)in 6 call sites across model APIs and helpers. - Keep error messages unchanged while standardizing the error class used.
vkarpov15
approved these changes
Mar 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces 6 instances of
throw new Error(...)withthrow new MongooseError(...)inlib/model.jsas part of the effort to standardize error types across the codebase.Changed locations:
useConnection()— missing connection argumentdeleteOne()— pre hook argument overwritebuildPreSavePromise()— pre save hook option overwrite in bulkSavebuildBulkWriteOperations()— invalid documents argument (2 instances)clientEncryption()— missing ClientEncryption in driverMongooseErrorextendsError, so this is fully backward-compatible.Testing
All 777 model-related tests pass.
Re: #15995