Skip to content

Commit 88815bb

Browse files
committed
error messages were refactored
1 parent 63b6d78 commit 88815bb

File tree

16 files changed

+109
-107
lines changed

16 files changed

+109
-107
lines changed

cluster.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ func (cfg *ClusterConfig) filterHost(host *HostInfo) bool {
335335
}
336336

337337
var (
338-
ErrNoHosts = errors.New("no hosts provided")
339-
ErrNoConnectionsStarted = errors.New("no connections were made when creating the session")
340-
ErrHostQueryFailed = errors.New("unable to populate Hosts")
338+
ErrAuthenticatorAndAuthProvider = errors.New("gocql: Can't use both Authenticator and AuthProvider in cluster config.")
339+
ErrNoHosts = errors.New("gocql: no hosts provided")
340+
ErrNoConnectionsStarted = errors.New("gocql: no connections were made when creating the session")
341341
)

conn.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ type PasswordAuthenticator struct {
8787

8888
func (p PasswordAuthenticator) Challenge(req []byte) ([]byte, Authenticator, error) {
8989
if !approve(string(req), p.AllowedAuthenticators) {
90-
return nil, nil, fmt.Errorf("unexpected authenticator %q", req)
90+
return nil, nil, fmt.Errorf("gocql: unexpected authenticator %q", req)
9191
}
9292
resp := make([]byte, 2+len(p.Username)+len(p.Password))
9393
resp[0] = 0
@@ -459,7 +459,7 @@ func (s *startupCoordinator) startup(ctx context.Context, supported map[string][
459459

460460
func (s *startupCoordinator) authenticateHandshake(ctx context.Context, authFrame *authenticateFrame, startupCompleted *atomic.Bool) error {
461461
if s.conn.auth == nil {
462-
return fmt.Errorf("authentication required (using %q)", authFrame.class)
462+
return fmt.Errorf("gocql: authentication required (using %q)", authFrame.class)
463463
}
464464

465465
resp, challenger, err := s.conn.auth.Challenge([]byte(authFrame.class))
@@ -492,7 +492,7 @@ func (s *startupCoordinator) authenticateHandshake(ctx context.Context, authFram
492492
data: resp,
493493
}
494494
default:
495-
return fmt.Errorf("unknown frame response during authentication: %v", v)
495+
return fmt.Errorf("gocql: unknown frame response during authentication: %v", v)
496496
}
497497
}
498498
}
@@ -1166,7 +1166,7 @@ func (c *Conn) addCall(call *callReq) error {
11661166
}
11671167
existingCall := c.calls[call.streamID]
11681168
if existingCall != nil {
1169-
return fmt.Errorf("attempting to use stream already in use: %d -> %d", call.streamID,
1169+
return fmt.Errorf("gocql: attempting to use stream already in use: %d -> %d", call.streamID,
11701170
existingCall.streamID)
11711171
}
11721172
c.calls[call.streamID] = call
@@ -1451,7 +1451,7 @@ func (c *Conn) prepareStatement(ctx context.Context, stmt string, tracer Tracer,
14511451
response: x.respMeta,
14521452
}
14531453
case error:
1454-
flight.err = x
1454+
flight.err = fmt.Errorf("cassandra: %w", x)
14551455
default:
14561456
flight.err = NewErrProtocol("Unknown type in response to prepare frame: %s", x)
14571457
}
@@ -1727,7 +1727,7 @@ func (c *Conn) UseKeyspace(keyspace string) error {
17271727
switch x := resp.(type) {
17281728
case *resultKeyspaceFrame:
17291729
case error:
1730-
return x
1730+
return fmt.Errorf("cassandra: %w", x)
17311731
default:
17321732
return NewErrProtocol("unknown frame in response to USE: %v", x)
17331733
}
@@ -1845,7 +1845,7 @@ func (c *Conn) executeBatch(ctx context.Context, batch *Batch) *Iter {
18451845

18461846
return iter
18471847
case error:
1848-
return &Iter{err: x, framer: framer}
1848+
return &Iter{err: fmt.Errorf("cassandra: %w", x), framer: framer}
18491849
default:
18501850
return &Iter{err: NewErrProtocol("Unknown type in response to batch statement: %s", x), framer: framer}
18511851
}

control.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func hostInfo(addr string, defaultPort int) ([]*HostInfo, error) {
159159
if err != nil {
160160
return nil, err
161161
} else if len(ips) == 0 {
162-
return nil, fmt.Errorf("no IP's returned from DNS lookup for %q", addr)
162+
return nil, fmt.Errorf("gocql: no IP's returned from DNS lookup for %q", addr)
163163
}
164164

165165
// Filter to v4 addresses if any present
@@ -284,7 +284,7 @@ func (c *controlConn) connect(hosts []*HostInfo) error {
284284
conn = nil
285285
}
286286
if conn == nil {
287-
return fmt.Errorf("unable to connect to initial hosts: %v", err)
287+
return fmt.Errorf("gocql: unable to connect to initial hosts: %w", err)
288288
}
289289

290290
// we could fetch the initial ring here and update initial host data. So that
@@ -311,11 +311,11 @@ func (c *controlConn) setupConn(conn *Conn) error {
311311
host = c.session.ring.addOrUpdate(host)
312312

313313
if c.session.cfg.filterHost(host) {
314-
return fmt.Errorf("host was filtered: %v", host.ConnectAddress())
314+
return fmt.Errorf("gocql: host was filtered: %v", host.ConnectAddress())
315315
}
316316

317317
if err := c.registerEvents(conn); err != nil {
318-
return fmt.Errorf("register events: %v", err)
318+
return fmt.Errorf("gocql: register events: %w", err)
319319
}
320320

321321
ch := &connHost{
@@ -365,7 +365,7 @@ func (c *controlConn) registerEvents(conn *Conn) error {
365365
if err != nil {
366366
return err
367367
} else if _, ok := frame.(*readyFrame); !ok {
368-
return fmt.Errorf("unexpected frame in response to register: got %T: %v\n", frame, frame)
368+
return fmt.Errorf("gocql: unexpected frame in response to register: got %T: %v\n", frame, frame)
369369
}
370370

371371
return nil
@@ -422,7 +422,7 @@ func (c *controlConn) attemptReconnect() (*Conn, error) {
422422
// changed their IPs while keeping the same hostname(s).
423423
initialHosts, resolvErr := addrsToHosts(c.session.cfg.Hosts, c.session.cfg.Port, c.session.logger)
424424
if resolvErr != nil {
425-
return nil, fmt.Errorf("resolve contact points' hostnames: %v", resolvErr)
425+
return nil, fmt.Errorf("gocql: resolve contact points' hostnames: %w", resolvErr)
426426
}
427427

428428
return c.attemptReconnectToAnyOfHosts(initialHosts)

dial.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ func (hd *defaultHostDialer) DialHost(ctx context.Context, host *HostInfo) (*Dia
6464
port := host.Port()
6565

6666
if !validIpAddr(ip) {
67-
return nil, fmt.Errorf("host missing connect ip address: %v", ip)
67+
return nil, fmt.Errorf("gocql: host missing connect ip address: %v", ip)
6868
} else if port == 0 {
69-
return nil, fmt.Errorf("host missing port: %v", port)
69+
return nil, fmt.Errorf("gocql: host missing port: %v", port)
7070
}
7171

7272
connAddr := host.ConnectAddressAndPort()

filters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func WhiteListHostFilter(hosts ...string) HostFilter {
7373
hostInfos, err := addrsToHosts(hosts, 9042, nopLogger{})
7474
if err != nil {
7575
// dont want to panic here, but rather not break the API
76-
panic(fmt.Errorf("unable to lookup host info from address: %v", err))
76+
panic(fmt.Errorf("gocql: unable to lookup host info from address: %w", err))
7777
}
7878

7979
m := make(map[string]bool, len(hostInfos))

0 commit comments

Comments
 (0)