Skip to content

Commit f498a53

Browse files
Add errorCoder compile check for mongo.ServerError
1 parent 03fda7a commit f498a53

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

mongo/errors.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ type LabeledError interface {
334334
HasErrorLabel(string) bool
335335
}
336336

337+
type errorCoder interface {
338+
ErrorCodes() []int
339+
}
340+
341+
var _ errorCoder = ServerError(nil)
342+
337343
// ServerError is the interface implemented by errors returned from the server. Custom implementations of this
338344
// interface should not be used in production.
339345
type ServerError interface {
@@ -910,7 +916,7 @@ func ErrorCodes(err error) []int {
910916
return nil
911917
}
912918

913-
var ec interface{ ErrorCodes() []int }
919+
var ec errorCoder
914920
if errors.As(wrapErrors(err), &ec) {
915921
return ec.ErrorCodes()
916922
}

mongo/errors_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ func (n netErr) Temporary() bool {
761761

762762
var _ net.Error = (*netErr)(nil)
763763

764-
func TestErrorCodesFrom(t *testing.T) {
764+
func TestErrorCodes(t *testing.T) {
765765
tests := []struct {
766766
name string
767767
input error

0 commit comments

Comments
 (0)