@@ -26,6 +26,7 @@ type expectedError struct {
26
26
IncludedLabels []string `bson:"errorLabelsContain"`
27
27
OmittedLabels []string `bson:"errorLabelsOmit"`
28
28
ExpectedResult * bson.RawValue `bson:"expectResult"`
29
+ ErrorResponse * bson.Raw `bson:"errorResponse"`
29
30
}
30
31
31
32
// verifyOperationError compares the expected error to the actual operation result. If the expected parameter is nil,
@@ -125,6 +126,19 @@ func verifyOperationError(ctx context.Context, expected *expectedError, result *
125
126
return fmt .Errorf ("result comparison error: %v" , err )
126
127
}
127
128
}
129
+
130
+ if expected .ErrorResponse != nil {
131
+ if details .raw == nil {
132
+ return fmt .Errorf ("expected error response from the server, got none" )
133
+ }
134
+
135
+ // Allow extra keys as 'errorResponse' functions like a root-level document.
136
+ gotValue := documentToRawValue (details .raw )
137
+ expectedValue := documentToRawValue (* expected .ErrorResponse )
138
+ if err := verifyValuesMatch (ctx , expectedValue , gotValue , true ); err != nil {
139
+ return fmt .Errorf ("error response comparison error: %v" , err )
140
+ }
141
+ }
128
142
return nil
129
143
}
130
144
@@ -133,6 +147,7 @@ type errorDetails struct {
133
147
codes []int32
134
148
codeNames []string
135
149
labels []string
150
+ raw bson.Raw
136
151
}
137
152
138
153
// extractErrorDetails creates an errorDetails instance based on the provided error. It returns the details and an "ok"
@@ -145,6 +160,7 @@ func extractErrorDetails(err error) (errorDetails, bool) {
145
160
details .codes = []int32 {converted .Code }
146
161
details .codeNames = []string {converted .Name }
147
162
details .labels = converted .Labels
163
+ details .raw = converted .Raw
148
164
case mongo.WriteException :
149
165
if converted .WriteConcernError != nil {
150
166
details .codes = append (details .codes , int32 (converted .WriteConcernError .Code ))
@@ -154,13 +170,15 @@ func extractErrorDetails(err error) (errorDetails, bool) {
154
170
details .codes = append (details .codes , int32 (we .Code ))
155
171
}
156
172
details .labels = converted .Labels
173
+ details .raw = converted .Raw
157
174
case mongo.BulkWriteException :
158
175
if converted .WriteConcernError != nil {
159
176
details .codes = append (details .codes , int32 (converted .WriteConcernError .Code ))
160
177
details .codeNames = append (details .codeNames , converted .WriteConcernError .Name )
161
178
}
162
179
for _ , we := range converted .WriteErrors {
163
180
details .codes = append (details .codes , int32 (we .Code ))
181
+ details .raw = we .Raw
164
182
}
165
183
details .labels = converted .Labels
166
184
default :
0 commit comments