Skip to content

Commit 9e4063a

Browse files
committed
Add redis prefix to errors
1 parent d31cf6c commit 9e4063a

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

options.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func ParseURL(redisURL string) (*Options, error) {
206206
case "unix":
207207
return setupUnixConn(u)
208208
default:
209-
return nil, fmt.Errorf("invalid redis URL scheme: %s", u.Scheme)
209+
return nil, fmt.Errorf("redis: invalid URL scheme: %s", u.Scheme)
210210
}
211211
}
212212

@@ -216,7 +216,7 @@ func setupTCPConn(u *url.URL) (*Options, error) {
216216
o.Username, o.Password = getUserPassword(u)
217217

218218
if len(u.Query()) > 0 {
219-
return nil, errors.New("no options supported")
219+
return nil, errors.New("redis: no options supported")
220220
}
221221

222222
h, p, err := net.SplitHostPort(u.Host)
@@ -239,10 +239,10 @@ func setupTCPConn(u *url.URL) (*Options, error) {
239239
o.DB = 0
240240
case 1:
241241
if o.DB, err = strconv.Atoi(f[0]); err != nil {
242-
return nil, fmt.Errorf("invalid redis database number: %q", f[0])
242+
return nil, fmt.Errorf("redis: invalid database number: %q", f[0])
243243
}
244244
default:
245-
return nil, fmt.Errorf("invalid redis URL path: %s", u.Path)
245+
return nil, fmt.Errorf("redis: invalid URL path: %s", u.Path)
246246
}
247247

248248
if u.Scheme == "rediss" {
@@ -258,7 +258,7 @@ func setupUnixConn(u *url.URL) (*Options, error) {
258258
}
259259

260260
if strings.TrimSpace(u.Path) == "" { // path is required with unix connection
261-
return nil, errors.New("empty redis unix socket path")
261+
return nil, errors.New("redis: empty unix socket path")
262262
}
263263
o.Addr = u.Path
264264

@@ -268,9 +268,10 @@ func setupUnixConn(u *url.URL) (*Options, error) {
268268
if dbStr == "" {
269269
return o, nil // if database is not set, connect to 0 db.
270270
}
271+
271272
db, err := strconv.Atoi(dbStr)
272273
if err != nil {
273-
return nil, fmt.Errorf("invalid reids database number: %s", err)
274+
return nil, fmt.Errorf("redis: invalid database number: %s", err)
274275
}
275276
o.DB = db
276277

options_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,37 +87,37 @@ func TestParseURL(t *testing.T) {
8787
{
8888
"unix://foo:bar@/tmp/redis.sock?db=test",
8989
"/tmp/redis.sock",
90-
0, false, errors.New("invalid reids database number: strconv.Atoi: parsing \"test\": invalid syntax"),
90+
0, false, errors.New("redis: invalid database number: strconv.Atoi: parsing \"test\": invalid syntax"),
9191
"", "",
9292
},
9393
{
9494
"redis://localhost/?abc=123",
9595
"",
96-
0, false, errors.New("no options supported"),
96+
0, false, errors.New("redis: no options supported"),
9797
"", "",
9898
},
9999
{
100100
"http://google.com",
101101
"",
102-
0, false, errors.New("invalid redis URL scheme: http"),
102+
0, false, errors.New("redis: invalid URL scheme: http"),
103103
"", "",
104104
},
105105
{
106106
"redis://localhost/1/2/3/4",
107107
"",
108-
0, false, errors.New("invalid redis URL path: /1/2/3/4"),
108+
0, false, errors.New("redis: invalid URL path: /1/2/3/4"),
109109
"", "",
110110
},
111111
{
112112
"12345",
113113
"",
114-
0, false, errors.New("invalid redis URL scheme: "),
114+
0, false, errors.New("redis: invalid URL scheme: "),
115115
"", "",
116116
},
117117
{
118118
"redis://localhost/iamadatabase",
119119
"",
120-
0, false, errors.New(`invalid redis database number: "iamadatabase"`),
120+
0, false, errors.New(`redis: invalid database number: "iamadatabase"`),
121121
"", "",
122122
},
123123
}

0 commit comments

Comments
 (0)