Skip to content

chore(aggregate): use MongooseError instead of Error#16095

Open
mahmoodhamdi wants to merge 1 commit intoAutomattic:masterfrom
mahmoodhamdi:chore/issue-15995-standardize-errors-aggregate
Open

chore(aggregate): use MongooseError instead of Error#16095
mahmoodhamdi wants to merge 1 commit intoAutomattic:masterfrom
mahmoodhamdi:chore/issue-15995-standardize-errors-aggregate

Conversation

@mahmoodhamdi
Copy link

Summary

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

MongooseError extends Error, so this is backward-compatible for any code catching generic Error instances.

Changed methods:

  • append() — invalid pipeline operator
  • addFields() — invalid argument type
  • project() — invalid argument type
  • unwind() — invalid argument type
  • redact() — invalid thenExpr/elseExpr value
  • explain() — empty pipeline
  • exec() — aggregate not bound to model

Testing

All 118 aggregate-related tests pass. Verified that thrown errors are instanceof MongooseError and still instanceof Error.

Re: #15995

Replace 7 instances of `throw new Error(...)` with
`throw new MongooseError(...)` in lib/aggregate.js for consistency.
MongooseError extends Error so this is backward-compatible for any
code catching generic Error instances.

Re: Automattic#15995
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.

1 participant