Skip to content

GODRIVER-2325 Expose raw server response in relevant errors #871

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

Merged
merged 5 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions mongo/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ func replaceErrors(err error) error {
Labels: de.Labels,
Name: de.Name,
Wrapped: de.Wrapped,
Raw: bson.Raw(de.Raw),
}
}
if qe, ok := err.(driver.QueryFailureError); ok {
// qe.Message is "command failure"
ce := CommandError{
Name: qe.Message,
Wrapped: qe.Wrapped,
Raw: bson.Raw(qe.Response),
}

dollarErr, err := qe.Response.LookupErr("$err")
Expand Down Expand Up @@ -218,6 +220,7 @@ type CommandError struct {
Labels []string // Categories to which the error belongs
Name string // A human-readable name corresponding to the error code
Wrapped error // The underlying error, if one exists.
Raw bson.Raw // The original server response containing the error.
}

// Error implements the error interface.
Expand Down Expand Up @@ -277,6 +280,9 @@ type WriteError struct {
Code int
Message string
Details bson.Raw

// The original write error from the server response.
Raw bson.Raw
}

func (we WriteError) Error() string {
Expand Down Expand Up @@ -332,6 +338,7 @@ func writeErrorsFromDriverWriteErrors(errs driver.WriteErrors) WriteErrors {
Code: int(err.Code),
Message: err.Message,
Details: bson.Raw(err.Details),
Raw: bson.Raw(err.Raw),
})
}
return wes
Expand All @@ -344,6 +351,7 @@ type WriteConcernError struct {
Code int
Message string
Details bson.Raw
Raw bson.Raw // The original write concern error from the server response.
}

// Error implements the error interface.
Expand All @@ -365,6 +373,9 @@ type WriteException struct {

// The categories to which the exception belongs.
Labels []string

// The original server response containing the error.
Raw bson.Raw
}

// Error implements the error interface.
Expand Down Expand Up @@ -451,6 +462,7 @@ func convertDriverWriteConcernError(wce *driver.WriteConcernError) *WriteConcern
Code: int(wce.Code),
Message: wce.Message,
Details: bson.Raw(wce.Details),
Raw: bson.Raw(wce.Raw),
}
}

Expand Down Expand Up @@ -584,6 +596,7 @@ func processWriteError(err error) (returnResult, error) {
WriteConcernError: convertDriverWriteConcernError(tt.WriteConcernError),
WriteErrors: writeErrorsFromDriverWriteErrors(tt.WriteErrors),
Labels: tt.Labels,
Raw: bson.Raw(tt.Raw),
}
default:
return rrNone, replaceErrors(err)
Expand Down
Loading