Skip to content

GODRIVER-2774 Refactor replaceErrors to always wrap errors instead of replacing them. #2113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

matthewdale
Copy link
Collaborator

@matthewdale matthewdale commented Jun 23, 2025

GODRIVER-2775

Summary

  • Rename replaceErrors to wrapErrors.
  • Update the logic in wrapErrors to wrap specific error values instead of replacing the top-level error.
    • Because the error assertions all use errors.Is/errors.As instead of type assertions, it may match more errors now. The possible effect is that the error may be wrapped in an additional top-level error. Error values are no longer discarded, so there should be no risk that a user's errors.Is/errors.As assertions will starting to fail.
  • Add Unwrap methods to mongo.MarshalError and mongo.MongocryptError so that the wrapped errors can be inspected using errors.Is/errors.As.
  • Remove duplicated error message from mongo.MarshalError and mongo.MongocryptError and always returne the error string from the wrapped error.
  • Append the error string from the Wrapped error to the error string returned by mongo.CommandError.

Background & Motivation

The approach in this PR reduces the likelihood of causing bugs by wrapping error values, which is one of the main goals. However, it doesn't try to answer some of the questions in GODRIVER-2775 or try to establish any new usability patterns for handling errors returned by the Go Driver APIs. We should defer those questions to GODRIVER-3602.

@mongodb-drivers-pr-bot mongodb-drivers-pr-bot bot added the priority-3-low Low Priority PR for Review label Jun 23, 2025
Copy link
Contributor

mongodb-drivers-pr-bot bot commented Jun 23, 2025

API Change Report

./v2/mongo

compatible changes

MarshalError.Unwrap: added
MongocryptError.Unwrap: added

@matthewdale matthewdale force-pushed the godriver2775-replaceerrors branch 3 times, most recently from bf769c0 to 374edb5 Compare June 26, 2025 02:18
@matthewdale matthewdale changed the title GODRIVER-2774 Refactor replaceErrors to use errors.Is/errors.As GODRIVER-2774 Refactor replaceErrors to always wrap errors instead of replacing them. Jun 26, 2025
@matthewdale matthewdale force-pushed the godriver2775-replaceerrors branch from 374edb5 to f3e687c Compare June 26, 2025 06:37
@matthewdale matthewdale marked this pull request as ready for review June 27, 2025 00:17
@matthewdale matthewdale requested a review from a team as a code owner June 27, 2025 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-3-low Low Priority PR for Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant