Skip to content

Commit 02eb68a

Browse files
AlekSijulienschmidt
authored andcommitted
Fix error message for unsupported isolation level. (#744)
* Fix error message for unsupported isolation level. It was "mysql: unsupported isolation level: \a" due to wrong conversion from int to string. See also golang/go#23632 * Add myself and sort authors.
1 parent 5890359 commit 02eb68a

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

AUTHORS

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
Aaron Hopkins <go-sql-driver at die.net>
1515
Achille Roussel <achille.roussel at gmail.com>
16+
Alexey Palazhchenko <alexey.palazhchenko at gmail.com>
1617
Arne Hormann <arnehormann at gmail.com>
1718
Asta Xie <xiemengjun at gmail.com>
1819
Bulat Gaifullin <gaifullinbf at gmail.com>
@@ -61,8 +62,8 @@ Paul Bonser <misterpib at gmail.com>
6162
Peter Schultz <peter.schultz at classmarkets.com>
6263
Rebecca Chin <rchin at pivotal.io>
6364
Reed Allman <rdallman10 at gmail.com>
64-
Runrioter Wung <runrioter at gmail.com>
6565
Robert Russell <robert at rrbrussell.com>
66+
Runrioter Wung <runrioter at gmail.com>
6667
Shuode Li <elemount at qq.com>
6768
Soroush Pour <me at soroushjp.com>
6869
Stan Putrya <root.vagner at gmail.com>
@@ -79,5 +80,6 @@ Counting Ltd.
7980
Google Inc.
8081
InfoSum Ltd.
8182
Keybase Inc.
83+
Percona LLC
8284
Pivotal Inc.
8385
Stripe Inc.

utils_go18.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"database/sql"
1616
"database/sql/driver"
1717
"errors"
18+
"fmt"
1819
)
1920

2021
func cloneTLSConfig(c *tls.Config) *tls.Config {
@@ -44,6 +45,6 @@ func mapIsolationLevel(level driver.IsolationLevel) (string, error) {
4445
case sql.LevelSerializable:
4546
return "SERIALIZABLE", nil
4647
default:
47-
return "", errors.New("mysql: unsupported isolation level: " + string(level))
48+
return "", fmt.Errorf("mysql: unsupported isolation level: %v", level)
4849
}
4950
}

utils_go18_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
)
1818

1919
func TestIsolationLevelMapping(t *testing.T) {
20-
2120
data := []struct {
2221
level driver.IsolationLevel
2322
expected string
@@ -47,8 +46,12 @@ func TestIsolationLevelMapping(t *testing.T) {
4746
}
4847

4948
// check unsupported mapping
50-
if actual, err := mapIsolationLevel(driver.IsolationLevel(sql.LevelLinearizable)); actual != "" || err == nil {
49+
expectedErr := "mysql: unsupported isolation level: 7"
50+
actual, err := mapIsolationLevel(driver.IsolationLevel(sql.LevelLinearizable))
51+
if actual != "" || err == nil {
5152
t.Fatal("Expected error on unsupported isolation level")
5253
}
53-
54+
if err.Error() != expectedErr {
55+
t.Fatalf("Expected error to be %q, got %q", expectedErr, err)
56+
}
5457
}

0 commit comments

Comments
 (0)