Skip to content

Commit 57747f8

Browse files
authored
GODRIVER-2325 Expose raw server response in relevant errors (#871)
1 parent f4a087a commit 57747f8

File tree

4 files changed

+151
-41
lines changed

4 files changed

+151
-41
lines changed

mongo/errors.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ func replaceErrors(err error) error {
5656
Labels: de.Labels,
5757
Name: de.Name,
5858
Wrapped: de.Wrapped,
59+
Raw: bson.Raw(de.Raw),
5960
}
6061
}
6162
if qe, ok := err.(driver.QueryFailureError); ok {
6263
// qe.Message is "command failure"
6364
ce := CommandError{
6465
Name: qe.Message,
6566
Wrapped: qe.Wrapped,
67+
Raw: bson.Raw(qe.Response),
6668
}
6769

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

223226
// Error implements the error interface.
@@ -277,6 +280,9 @@ type WriteError struct {
277280
Code int
278281
Message string
279282
Details bson.Raw
283+
284+
// The original write error from the server response.
285+
Raw bson.Raw
280286
}
281287

282288
func (we WriteError) Error() string {
@@ -332,6 +338,7 @@ func writeErrorsFromDriverWriteErrors(errs driver.WriteErrors) WriteErrors {
332338
Code: int(err.Code),
333339
Message: err.Message,
334340
Details: bson.Raw(err.Details),
341+
Raw: bson.Raw(err.Raw),
335342
})
336343
}
337344
return wes
@@ -344,6 +351,7 @@ type WriteConcernError struct {
344351
Code int
345352
Message string
346353
Details bson.Raw
354+
Raw bson.Raw // The original write concern error from the server response.
347355
}
348356

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

366374
// The categories to which the exception belongs.
367375
Labels []string
376+
377+
// The original server response containing the error.
378+
Raw bson.Raw
368379
}
369380

370381
// Error implements the error interface.
@@ -451,6 +462,7 @@ func convertDriverWriteConcernError(wce *driver.WriteConcernError) *WriteConcern
451462
Code: int(wce.Code),
452463
Message: wce.Message,
453464
Details: bson.Raw(wce.Details),
465+
Raw: bson.Raw(wce.Raw),
454466
}
455467
}
456468

@@ -584,6 +596,7 @@ func processWriteError(err error) (returnResult, error) {
584596
WriteConcernError: convertDriverWriteConcernError(tt.WriteConcernError),
585597
WriteErrors: writeErrorsFromDriverWriteErrors(tt.WriteErrors),
586598
Labels: tt.Labels,
599+
Raw: bson.Raw(tt.Raw),
587600
}
588601
default:
589602
return rrNone, replaceErrors(err)

0 commit comments

Comments
 (0)