File tree 3 files changed +27
-0
lines changed
3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ Asta Xie <xiemengjun at gmail.com>
23
23
Bulat Gaifullin <gaifullinbf at gmail.com>
24
24
Caine Jette <jette at alum.mit.edu>
25
25
Carlos Nieto <jose.carlos at menteslibres.net>
26
+ Chris Kirkland <chriskirkland at github.com>
26
27
Chris Moos <chris at tech9computers.com>
27
28
Craig Wilson <craiggwilson at gmail.com>
28
29
Daniel Montoya <dsmontoyam at gmail.com>
Original file line number Diff line number Diff line change @@ -63,3 +63,10 @@ type MySQLError struct {
63
63
func (me * MySQLError ) Error () string {
64
64
return fmt .Sprintf ("Error %d: %s" , me .Number , me .Message )
65
65
}
66
+
67
+ func (me * MySQLError ) Is (err error ) bool {
68
+ if merr , ok := err .(* MySQLError ); ok {
69
+ return merr .Number == me .Number
70
+ }
71
+ return false
72
+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ package mysql
10
10
11
11
import (
12
12
"bytes"
13
+ "errors"
13
14
"log"
14
15
"testing"
15
16
)
@@ -40,3 +41,21 @@ func TestErrorsStrictIgnoreNotes(t *testing.T) {
40
41
dbt .mustExec ("DROP TABLE IF EXISTS does_not_exist" )
41
42
})
42
43
}
44
+
45
+ func TestMySQLErrIs (t * testing.T ) {
46
+ infraErr := & MySQLError {1234 , "the server is on fire" }
47
+ otherInfraErr := & MySQLError {1234 , "the datacenter is flooded" }
48
+ if ! errors .Is (infraErr , otherInfraErr ) {
49
+ t .Errorf ("expected errors to be the same: %+v %+v" , infraErr , otherInfraErr )
50
+ }
51
+
52
+ differentCodeErr := & MySQLError {5678 , "the server is on fire" }
53
+ if errors .Is (infraErr , differentCodeErr ) {
54
+ t .Fatalf ("expected errors to be different: %+v %+v" , infraErr , differentCodeErr )
55
+ }
56
+
57
+ nonMysqlErr := errors .New ("not a mysql error" )
58
+ if errors .Is (infraErr , nonMysqlErr ) {
59
+ t .Fatalf ("expected errors to be different: %+v %+v" , infraErr , nonMysqlErr )
60
+ }
61
+ }
You can’t perform that action at this time.
0 commit comments