Skip to content

Commit c7e11e4

Browse files
committed
error messages were refactored
1 parent bf16ec3 commit c7e11e4

16 files changed

+105
-101
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
@@ -86,7 +86,7 @@ type PasswordAuthenticator struct {
8686

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

469469
func (s *startupCoordinator) authenticateHandshake(ctx context.Context, authFrame *authenticateFrame) error {
470470
if s.conn.auth == nil {
471-
return fmt.Errorf("authentication required (using %q)", authFrame.class)
471+
return fmt.Errorf("gocql: authentication required (using %q)", authFrame.class)
472472
}
473473

474474
resp, challenger, err := s.conn.auth.Challenge([]byte(authFrame.class))
@@ -501,7 +501,7 @@ func (s *startupCoordinator) authenticateHandshake(ctx context.Context, authFram
501501
data: resp,
502502
}
503503
default:
504-
return fmt.Errorf("unknown frame response during authentication: %v", v)
504+
return fmt.Errorf("gocql: unknown frame response during authentication: %v", v)
505505
}
506506
}
507507
}
@@ -1003,7 +1003,7 @@ func (c *Conn) addCall(call *callReq) error {
10031003
}
10041004
existingCall := c.calls[call.streamID]
10051005
if existingCall != nil {
1006-
return fmt.Errorf("attempting to use stream already in use: %d -> %d", call.streamID,
1006+
return fmt.Errorf("gocql: attempting to use stream already in use: %d -> %d", call.streamID,
10071007
existingCall.streamID)
10081008
}
10091009
c.calls[call.streamID] = call
@@ -1275,7 +1275,7 @@ func (c *Conn) prepareStatement(ctx context.Context, stmt string, tracer Tracer)
12751275
response: x.respMeta,
12761276
}
12771277
case error:
1278-
flight.err = x
1278+
flight.err = fmt.Errorf("cassandra: %w", x)
12791279
default:
12801280
flight.err = NewErrProtocol("Unknown type in response to prepare frame: %s", x)
12811281
}
@@ -1513,7 +1513,7 @@ func (c *Conn) UseKeyspace(keyspace string) error {
15131513
switch x := resp.(type) {
15141514
case *resultKeyspaceFrame:
15151515
case error:
1516-
return x
1516+
return fmt.Errorf("cassandra: %w", x)
15171517
default:
15181518
return NewErrProtocol("unknown frame in response to USE: %v", x)
15191519
}
@@ -1621,7 +1621,7 @@ func (c *Conn) executeBatch(ctx context.Context, batch *Batch) *Iter {
16211621

16221622
return iter
16231623
case error:
1624-
return &Iter{err: x, framer: framer}
1624+
return &Iter{err: fmt.Errorf("cassandra: %w", x), framer: framer}
16251625
default:
16261626
return &Iter{err: NewErrProtocol("Unknown type in response to batch statement: %s", x), framer: framer}
16271627
}

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))

frame.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func (c *Consistency) UnmarshalText(text []byte) error {
254254
case "LOCAL_ONE":
255255
*c = LocalOne
256256
default:
257-
return fmt.Errorf("invalid consistency %q", string(text))
257+
return fmt.Errorf("gocql: invalid consistency %q", string(text))
258258
}
259259

260260
return nil
@@ -304,7 +304,7 @@ func (s *SerialConsistency) UnmarshalText(text []byte) error {
304304
case "LOCAL_SERIAL":
305305
*s = LocalSerial
306306
default:
307-
return fmt.Errorf("invalid consistency %q", string(text))
307+
return fmt.Errorf("gocql: invalid consistency %q", string(text))
308308
}
309309

310310
return nil
@@ -315,7 +315,7 @@ const (
315315
)
316316

317317
var (
318-
ErrFrameTooBig = errors.New("frame length is bigger than the maximum allowed")
318+
ErrFrameTooBig = errors.New("gocql: frame length is bigger than the maximum allowed")
319319
)
320320

321321
const maxFrameHeaderSize = 9
@@ -458,15 +458,15 @@ func readHeader(r io.Reader, p []byte) (head frameHeader, err error) {
458458

459459
if version > protoVersion2 {
460460
if len(p) != 9 {
461-
return frameHeader{}, fmt.Errorf("not enough bytes to read header require 9 got: %d", len(p))
461+
return frameHeader{}, fmt.Errorf("gocql: not enough bytes to read header require 9 got: %d", len(p))
462462
}
463463

464464
head.stream = int(int16(p[2])<<8 | int16(p[3]))
465465
head.op = frameOp(p[4])
466466
head.length = int(readInt(p[5:]))
467467
} else {
468468
if len(p) != 8 {
469-
return frameHeader{}, fmt.Errorf("not enough bytes to read header require 8 got: %d", len(p))
469+
return frameHeader{}, fmt.Errorf("gocql: not enough bytes to read header require 8 got: %d", len(p))
470470
}
471471

472472
head.stream = int(int8(p[2]))
@@ -490,12 +490,12 @@ func (f *framer) payload() {
490490
// reads a frame form the wire into the framers buffer
491491
func (f *framer) readFrame(r io.Reader, head *frameHeader) error {
492492
if head.length < 0 {
493-
return fmt.Errorf("frame body length can not be less than 0: %d", head.length)
493+
return fmt.Errorf("gocql: frame body length can not be less than 0: %d", head.length)
494494
} else if head.length > maxFrameSize {
495495
// need to free up the connection to be used again
496496
_, err := io.CopyN(ioutil.Discard, r, int64(head.length))
497497
if err != nil {
498-
return fmt.Errorf("error whilst trying to discard frame with invalid length: %v", err)
498+
return fmt.Errorf("gocql: error whilst trying to discard frame with invalid length: %w", err)
499499
}
500500
return ErrFrameTooBig
501501
}
@@ -510,7 +510,7 @@ func (f *framer) readFrame(r io.Reader, head *frameHeader) error {
510510
// assume the underlying reader takes care of timeouts and retries
511511
n, err := io.ReadFull(r, f.buf)
512512
if err != nil {
513-
return fmt.Errorf("unable to read frame body: read %d/%d bytes: %v", n, head.length, err)
513+
return fmt.Errorf("gocql: unable to read frame body: read %d/%d bytes: %w", n, head.length, err)
514514
}
515515

516516
if head.flags&flagCompress == flagCompress {
@@ -520,7 +520,7 @@ func (f *framer) readFrame(r io.Reader, head *frameHeader) error {
520520

521521
f.buf, err = f.compres.Decode(f.buf)
522522
if err != nil {
523-
return err
523+
return fmt.Errorf("gocql: %w", err)
524524
}
525525
}
526526

@@ -696,7 +696,7 @@ func (f *framer) parseErrorFrame() frame {
696696
// TODO(zariel): we should have some distinct types for these errors
697697
return errD
698698
default:
699-
panic(fmt.Errorf("unknown error code: 0x%x", errD.code))
699+
panic(fmt.Errorf("gocql: unknown error code: 0x%x", errD.code))
700700
}
701701
}
702702

@@ -765,7 +765,7 @@ func (f *framer) finish() error {
765765
// TODO: only compress frames which are big enough
766766
compressed, err := f.compres.Encode(f.buf[f.headSize:])
767767
if err != nil {
768-
return err
768+
return fmt.Errorf("gocql: %w", err)
769769
}
770770

771771
f.buf = append(f.buf[:f.headSize], compressed...)
@@ -845,7 +845,7 @@ func (w *writePrepareFrame) buildFrame(f *framer, streamID int) error {
845845
if f.proto > protoVersion4 {
846846
flags |= flagWithPreparedKeyspace
847847
} else {
848-
panic(fmt.Errorf("the keyspace can only be set with protocol 5 or higher"))
848+
panic(fmt.Errorf("gocql: the keyspace can only be set with protocol 5 or higher"))
849849
}
850850
}
851851
if f.proto > protoVersion4 {
@@ -944,7 +944,7 @@ func (f *framer) parsePreparedMetadata() preparedMetadata {
944944
meta.flags = f.readInt()
945945
meta.colCount = f.readInt()
946946
if meta.colCount < 0 {
947-
panic(fmt.Errorf("received negative column count: %d", meta.colCount))
947+
panic(fmt.Errorf("gocql: received negative column count: %d", meta.colCount))
948948
}
949949
meta.actualColCount = meta.colCount
950950

@@ -1041,7 +1041,7 @@ func (f *framer) parseResultMetadata() resultMetadata {
10411041
meta.flags = f.readInt()
10421042
meta.colCount = f.readInt()
10431043
if meta.colCount < 0 {
1044-
panic(fmt.Errorf("received negative column count: %d", meta.colCount))
1044+
panic(fmt.Errorf("gocql: received negative column count: %d", meta.colCount))
10451045
}
10461046
meta.actualColCount = meta.colCount
10471047

@@ -1128,7 +1128,7 @@ func (f *framer) parseResultRows() frame {
11281128

11291129
result.numRows = f.readInt()
11301130
if result.numRows < 0 {
1131-
panic(fmt.Errorf("invalid row_count in result frame: %d", result.numRows))
1131+
panic(fmt.Errorf("gocql: invalid row_count in result frame: %d", result.numRows))
11321132
}
11331133

11341134
return result
@@ -1496,7 +1496,7 @@ func (f *framer) writeQueryParams(opts *queryParams) {
14961496
if f.proto > protoVersion4 {
14971497
flags |= flagWithKeyspace
14981498
} else {
1499-
panic(fmt.Errorf("the keyspace can only be set with protocol 5 or higher"))
1499+
panic(fmt.Errorf("gocql: the keyspace can only be set with protocol 5 or higher"))
15001500
}
15011501
}
15021502

@@ -1759,7 +1759,7 @@ func (f *framer) writeRegisterFrame(streamID int, w *writeRegisterFrame) error {
17591759

17601760
func (f *framer) readByte() byte {
17611761
if len(f.buf) < 1 {
1762-
panic(fmt.Errorf("not enough bytes in buffer to read byte require 1 got: %d", len(f.buf)))
1762+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read byte require 1 got: %d", len(f.buf)))
17631763
}
17641764

17651765
b := f.buf[0]
@@ -1769,7 +1769,7 @@ func (f *framer) readByte() byte {
17691769

17701770
func (f *framer) readInt() (n int) {
17711771
if len(f.buf) < 4 {
1772-
panic(fmt.Errorf("not enough bytes in buffer to read int require 4 got: %d", len(f.buf)))
1772+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read int require 4 got: %d", len(f.buf)))
17731773
}
17741774

17751775
n = int(int32(f.buf[0])<<24 | int32(f.buf[1])<<16 | int32(f.buf[2])<<8 | int32(f.buf[3]))
@@ -1779,7 +1779,7 @@ func (f *framer) readInt() (n int) {
17791779

17801780
func (f *framer) readShort() (n uint16) {
17811781
if len(f.buf) < 2 {
1782-
panic(fmt.Errorf("not enough bytes in buffer to read short require 2 got: %d", len(f.buf)))
1782+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read short require 2 got: %d", len(f.buf)))
17831783
}
17841784
n = uint16(f.buf[0])<<8 | uint16(f.buf[1])
17851785
f.buf = f.buf[2:]
@@ -1790,7 +1790,7 @@ func (f *framer) readString() (s string) {
17901790
size := f.readShort()
17911791

17921792
if len(f.buf) < int(size) {
1793-
panic(fmt.Errorf("not enough bytes in buffer to read string require %d got: %d", size, len(f.buf)))
1793+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read string require %d got: %d", size, len(f.buf)))
17941794
}
17951795

17961796
s = string(f.buf[:size])
@@ -1802,7 +1802,7 @@ func (f *framer) readLongString() (s string) {
18021802
size := f.readInt()
18031803

18041804
if len(f.buf) < size {
1805-
panic(fmt.Errorf("not enough bytes in buffer to read long string require %d got: %d", size, len(f.buf)))
1805+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read long string require %d got: %d", size, len(f.buf)))
18061806
}
18071807

18081808
s = string(f.buf[:size])
@@ -1812,7 +1812,7 @@ func (f *framer) readLongString() (s string) {
18121812

18131813
func (f *framer) readUUID() *UUID {
18141814
if len(f.buf) < 16 {
1815-
panic(fmt.Errorf("not enough bytes in buffer to read uuid require %d got: %d", 16, len(f.buf)))
1815+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read uuid require %d got: %d", 16, len(f.buf)))
18161816
}
18171817

18181818
// TODO: how to handle this error, if it is a uuid, then sureley, problems?
@@ -1839,7 +1839,7 @@ func (f *framer) readBytesInternal() ([]byte, error) {
18391839
}
18401840

18411841
if len(f.buf) < size {
1842-
return nil, fmt.Errorf("not enough bytes in buffer to read bytes require %d got: %d", size, len(f.buf))
1842+
return nil, fmt.Errorf("gocql: not enough bytes in buffer to read bytes require %d got: %d", size, len(f.buf))
18431843
}
18441844

18451845
l := f.buf[:size]
@@ -1860,7 +1860,7 @@ func (f *framer) readBytes() []byte {
18601860
func (f *framer) readShortBytes() []byte {
18611861
size := f.readShort()
18621862
if len(f.buf) < int(size) {
1863-
panic(fmt.Errorf("not enough bytes in buffer to read short bytes: require %d got %d", size, len(f.buf)))
1863+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read short bytes: require %d got %d", size, len(f.buf)))
18641864
}
18651865

18661866
l := f.buf[:size]
@@ -1871,18 +1871,18 @@ func (f *framer) readShortBytes() []byte {
18711871

18721872
func (f *framer) readInetAdressOnly() net.IP {
18731873
if len(f.buf) < 1 {
1874-
panic(fmt.Errorf("not enough bytes in buffer to read inet size require %d got: %d", 1, len(f.buf)))
1874+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read inet size require %d got: %d", 1, len(f.buf)))
18751875
}
18761876

18771877
size := f.buf[0]
18781878
f.buf = f.buf[1:]
18791879

18801880
if !(size == 4 || size == 16) {
1881-
panic(fmt.Errorf("invalid IP size: %d", size))
1881+
panic(fmt.Errorf("gocql: invalid IP size: %d", size))
18821882
}
18831883

18841884
if len(f.buf) < 1 {
1885-
panic(fmt.Errorf("not enough bytes in buffer to read inet require %d got: %d", size, len(f.buf)))
1885+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read inet require %d got: %d", size, len(f.buf)))
18861886
}
18871887

18881888
ip := make([]byte, size)

helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func goType(t TypeInfo) (reflect.Type, error) {
9797
case TypeDuration:
9898
return reflect.TypeOf(*new(Duration)), nil
9999
default:
100-
return nil, fmt.Errorf("cannot create Go type for unknown CQL type %s", t)
100+
return nil, fmt.Errorf("gocql: cannot create Go type for unknown CQL type %s", t)
101101
}
102102
}
103103

0 commit comments

Comments
 (0)