GODRIVER-2774 Refactor replaceErrors to always wrap errors instead of replacing them. #2113
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.
GODRIVER-2775
Summary
replaceErrors
towrapErrors
.wrapErrors
to wrap specific error values instead of replacing the top-level error.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'serrors.Is
/errors.As
assertions will starting to fail.Unwrap
methods tomongo.MarshalError
andmongo.MongocryptError
so that the wrapped errors can be inspected usingerrors.Is
/errors.As
.mongo.MarshalError
andmongo.MongocryptError
and always returne the error string from the wrapped error.Wrapped
error to the error string returned bymongo.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.