Skip to content

Commit 516f6e3

Browse files
tengu-alttengu-alt
authored andcommitted
error messages were refactored
1 parent 953e0df commit 516f6e3

File tree

16 files changed

+103
-97
lines changed

16 files changed

+103
-97
lines changed

cluster.go

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

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

conn.go

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

9595
func (p PasswordAuthenticator) Challenge(req []byte) ([]byte, Authenticator, error) {
9696
if !approve(string(req), p.AllowedAuthenticators) {
97-
return nil, nil, fmt.Errorf("unexpected authenticator %q", req)
97+
return nil, nil, fmt.Errorf("gocql: unexpected authenticator %q", req)
9898
}
9999
resp := make([]byte, 2+len(p.Username)+len(p.Password))
100100
resp[0] = 0
@@ -484,7 +484,7 @@ func (s *startupCoordinator) startup(ctx context.Context, supported map[string][
484484

485485
func (s *startupCoordinator) authenticateHandshake(ctx context.Context, authFrame *authenticateFrame) error {
486486
if s.conn.auth == nil {
487-
return fmt.Errorf("authentication required (using %q)", authFrame.class)
487+
return fmt.Errorf("gocql: authentication required (using %q)", authFrame.class)
488488
}
489489

490490
resp, challenger, err := s.conn.auth.Challenge([]byte(authFrame.class))
@@ -517,7 +517,7 @@ func (s *startupCoordinator) authenticateHandshake(ctx context.Context, authFram
517517
data: resp,
518518
}
519519
default:
520-
return fmt.Errorf("unknown frame response during authentication: %v", v)
520+
return fmt.Errorf("gocql: unknown frame response during authentication: %v", v)
521521
}
522522
}
523523
}
@@ -1019,7 +1019,7 @@ func (c *Conn) addCall(call *callReq) error {
10191019
}
10201020
existingCall := c.calls[call.streamID]
10211021
if existingCall != nil {
1022-
return fmt.Errorf("attempting to use stream already in use: %d -> %d", call.streamID,
1022+
return fmt.Errorf("gocql: attempting to use stream already in use: %d -> %d", call.streamID,
10231023
existingCall.streamID)
10241024
}
10251025
c.calls[call.streamID] = call
@@ -1291,7 +1291,7 @@ func (c *Conn) prepareStatement(ctx context.Context, stmt string, tracer Tracer)
12911291
response: x.respMeta,
12921292
}
12931293
case error:
1294-
flight.err = x
1294+
flight.err = fmt.Errorf("cassandra: %w", x)
12951295
default:
12961296
flight.err = NewErrProtocol("Unknown type in response to prepare frame: %s", x)
12971297
}
@@ -1528,7 +1528,7 @@ func (c *Conn) UseKeyspace(keyspace string) error {
15281528
switch x := resp.(type) {
15291529
case *resultKeyspaceFrame:
15301530
case error:
1531-
return x
1531+
return fmt.Errorf("cassandra: %w", x)
15321532
default:
15331533
return NewErrProtocol("unknown frame in response to USE: %v", x)
15341534
}
@@ -1636,7 +1636,7 @@ func (c *Conn) executeBatch(ctx context.Context, batch *Batch) *Iter {
16361636

16371637
return iter
16381638
case error:
1639-
return &Iter{err: x, framer: framer}
1639+
return &Iter{err: fmt.Errorf("cassandra: %w", x), framer: framer}
16401640
default:
16411641
return &Iter{err: NewErrProtocol("Unknown type in response to batch statement: %s", x), framer: framer}
16421642
}

control.go

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

161161
// Filter to v4 addresses if any present
@@ -275,7 +275,7 @@ func (c *controlConn) connect(hosts []*HostInfo) error {
275275
conn = nil
276276
}
277277
if conn == nil {
278-
return fmt.Errorf("unable to connect to initial hosts: %v", err)
278+
return fmt.Errorf("gocql: unable to connect to initial hosts: %w", err)
279279
}
280280

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

304304
if c.session.cfg.filterHost(host) {
305-
return fmt.Errorf("host was filtered: %v", host.ConnectAddress())
305+
return fmt.Errorf("gocql: host was filtered: %v", host.ConnectAddress())
306306
}
307307

308308
if err := c.registerEvents(conn); err != nil {
309-
return fmt.Errorf("register events: %v", err)
309+
return fmt.Errorf("gocql: register events: %w", err)
310310
}
311311

312312
ch := &connHost{
@@ -356,7 +356,7 @@ func (c *controlConn) registerEvents(conn *Conn) error {
356356
if err != nil {
357357
return err
358358
} else if _, ok := frame.(*readyFrame); !ok {
359-
return fmt.Errorf("unexpected frame in response to register: got %T: %v\n", frame, frame)
359+
return fmt.Errorf("gocql: unexpected frame in response to register: got %T: %v\n", frame, frame)
360360
}
361361

362362
return nil
@@ -413,7 +413,7 @@ func (c *controlConn) attemptReconnect() (*Conn, error) {
413413
// changed their IPs while keeping the same hostname(s).
414414
initialHosts, resolvErr := addrsToHosts(c.session.cfg.Hosts, c.session.cfg.Port, c.session.logger)
415415
if resolvErr != nil {
416-
return nil, fmt.Errorf("resolve contact points' hostnames: %v", resolvErr)
416+
return nil, fmt.Errorf("gocql: resolve contact points' hostnames: %w", resolvErr)
417417
}
418418

419419
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
@@ -67,7 +67,7 @@ func WhiteListHostFilter(hosts ...string) HostFilter {
6767
hostInfos, err := addrsToHosts(hosts, 9042, nopLogger{})
6868
if err != nil {
6969
// dont want to panic here, but rather not break the API
70-
panic(fmt.Errorf("unable to lookup host info from address: %v", err))
70+
panic(fmt.Errorf("gocql: unable to lookup host info from address: %w", err))
7171
}
7272

7373
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
@@ -315,7 +315,7 @@ func (s *SerialConsistency) UnmarshalText(text []byte) error {
315315
case "LOCAL_SERIAL":
316316
*s = LocalSerial
317317
default:
318-
return fmt.Errorf("invalid consistency %q", string(text))
318+
return fmt.Errorf("gocql: invalid consistency %q", string(text))
319319
}
320320

321321
return nil
@@ -326,7 +326,7 @@ const (
326326
)
327327

328328
var (
329-
ErrFrameTooBig = errors.New("frame length is bigger than the maximum allowed")
329+
ErrFrameTooBig = errors.New("gocql: frame length is bigger than the maximum allowed")
330330
)
331331

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

470470
if version > protoVersion2 {
471471
if len(p) != 9 {
472-
return frameHeader{}, fmt.Errorf("not enough bytes to read header require 9 got: %d", len(p))
472+
return frameHeader{}, fmt.Errorf("gocql: not enough bytes to read header require 9 got: %d", len(p))
473473
}
474474

475475
head.stream = int(int16(p[2])<<8 | int16(p[3]))
476476
head.op = frameOp(p[4])
477477
head.length = int(readInt(p[5:]))
478478
} else {
479479
if len(p) != 8 {
480-
return frameHeader{}, fmt.Errorf("not enough bytes to read header require 8 got: %d", len(p))
480+
return frameHeader{}, fmt.Errorf("gocql: not enough bytes to read header require 8 got: %d", len(p))
481481
}
482482

483483
head.stream = int(int8(p[2]))
@@ -501,12 +501,12 @@ func (f *framer) payload() {
501501
// reads a frame form the wire into the framers buffer
502502
func (f *framer) readFrame(r io.Reader, head *frameHeader) error {
503503
if head.length < 0 {
504-
return fmt.Errorf("frame body length can not be less than 0: %d", head.length)
504+
return fmt.Errorf("gocql: frame body length can not be less than 0: %d", head.length)
505505
} else if head.length > maxFrameSize {
506506
// need to free up the connection to be used again
507507
_, err := io.CopyN(ioutil.Discard, r, int64(head.length))
508508
if err != nil {
509-
return fmt.Errorf("error whilst trying to discard frame with invalid length: %v", err)
509+
return fmt.Errorf("gocql: error whilst trying to discard frame with invalid length: %w", err)
510510
}
511511
return ErrFrameTooBig
512512
}
@@ -521,7 +521,7 @@ func (f *framer) readFrame(r io.Reader, head *frameHeader) error {
521521
// assume the underlying reader takes care of timeouts and retries
522522
n, err := io.ReadFull(r, f.buf)
523523
if err != nil {
524-
return fmt.Errorf("unable to read frame body: read %d/%d bytes: %v", n, head.length, err)
524+
return fmt.Errorf("gocql: unable to read frame body: read %d/%d bytes: %w", n, head.length, err)
525525
}
526526

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

532532
f.buf, err = f.compres.Decode(f.buf)
533533
if err != nil {
534-
return err
534+
return fmt.Errorf("gocql: %w", err)
535535
}
536536
}
537537

@@ -707,7 +707,7 @@ func (f *framer) parseErrorFrame() frame {
707707
// TODO(zariel): we should have some distinct types for these errors
708708
return errD
709709
default:
710-
panic(fmt.Errorf("unknown error code: 0x%x", errD.code))
710+
panic(fmt.Errorf("gocql: unknown error code: 0x%x", errD.code))
711711
}
712712
}
713713

@@ -776,7 +776,7 @@ func (f *framer) finish() error {
776776
// TODO: only compress frames which are big enough
777777
compressed, err := f.compres.Encode(f.buf[f.headSize:])
778778
if err != nil {
779-
return err
779+
return fmt.Errorf("gocql: %w", err)
780780
}
781781

782782
f.buf = append(f.buf[:f.headSize], compressed...)
@@ -856,7 +856,7 @@ func (w *writePrepareFrame) buildFrame(f *framer, streamID int) error {
856856
if f.proto > protoVersion4 {
857857
flags |= flagWithPreparedKeyspace
858858
} else {
859-
panic(fmt.Errorf("the keyspace can only be set with protocol 5 or higher"))
859+
panic(fmt.Errorf("gocql: the keyspace can only be set with protocol 5 or higher"))
860860
}
861861
}
862862
if f.proto > protoVersion4 {
@@ -955,7 +955,7 @@ func (f *framer) parsePreparedMetadata() preparedMetadata {
955955
meta.flags = f.readInt()
956956
meta.colCount = f.readInt()
957957
if meta.colCount < 0 {
958-
panic(fmt.Errorf("received negative column count: %d", meta.colCount))
958+
panic(fmt.Errorf("gocql: received negative column count: %d", meta.colCount))
959959
}
960960
meta.actualColCount = meta.colCount
961961

@@ -1052,7 +1052,7 @@ func (f *framer) parseResultMetadata() resultMetadata {
10521052
meta.flags = f.readInt()
10531053
meta.colCount = f.readInt()
10541054
if meta.colCount < 0 {
1055-
panic(fmt.Errorf("received negative column count: %d", meta.colCount))
1055+
panic(fmt.Errorf("gocql: received negative column count: %d", meta.colCount))
10561056
}
10571057
meta.actualColCount = meta.colCount
10581058

@@ -1139,7 +1139,7 @@ func (f *framer) parseResultRows() frame {
11391139

11401140
result.numRows = f.readInt()
11411141
if result.numRows < 0 {
1142-
panic(fmt.Errorf("invalid row_count in result frame: %d", result.numRows))
1142+
panic(fmt.Errorf("gocql: invalid row_count in result frame: %d", result.numRows))
11431143
}
11441144

11451145
return result
@@ -1507,7 +1507,7 @@ func (f *framer) writeQueryParams(opts *queryParams) {
15071507
if f.proto > protoVersion4 {
15081508
flags |= flagWithKeyspace
15091509
} else {
1510-
panic(fmt.Errorf("the keyspace can only be set with protocol 5 or higher"))
1510+
panic(fmt.Errorf("gocql: the keyspace can only be set with protocol 5 or higher"))
15111511
}
15121512
}
15131513

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

17711771
func (f *framer) readByte() byte {
17721772
if len(f.buf) < 1 {
1773-
panic(fmt.Errorf("not enough bytes in buffer to read byte require 1 got: %d", len(f.buf)))
1773+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read byte require 1 got: %d", len(f.buf)))
17741774
}
17751775

17761776
b := f.buf[0]
@@ -1780,7 +1780,7 @@ func (f *framer) readByte() byte {
17801780

17811781
func (f *framer) readInt() (n int) {
17821782
if len(f.buf) < 4 {
1783-
panic(fmt.Errorf("not enough bytes in buffer to read int require 4 got: %d", len(f.buf)))
1783+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read int require 4 got: %d", len(f.buf)))
17841784
}
17851785

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

17911791
func (f *framer) readShort() (n uint16) {
17921792
if len(f.buf) < 2 {
1793-
panic(fmt.Errorf("not enough bytes in buffer to read short require 2 got: %d", len(f.buf)))
1793+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read short require 2 got: %d", len(f.buf)))
17941794
}
17951795
n = uint16(f.buf[0])<<8 | uint16(f.buf[1])
17961796
f.buf = f.buf[2:]
@@ -1801,7 +1801,7 @@ func (f *framer) readString() (s string) {
18011801
size := f.readShort()
18021802

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

18071807
s = string(f.buf[:size])
@@ -1813,7 +1813,7 @@ func (f *framer) readLongString() (s string) {
18131813
size := f.readInt()
18141814

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

18191819
s = string(f.buf[:size])
@@ -1823,7 +1823,7 @@ func (f *framer) readLongString() (s string) {
18231823

18241824
func (f *framer) readUUID() *UUID {
18251825
if len(f.buf) < 16 {
1826-
panic(fmt.Errorf("not enough bytes in buffer to read uuid require %d got: %d", 16, len(f.buf)))
1826+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read uuid require %d got: %d", 16, len(f.buf)))
18271827
}
18281828

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

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

18561856
l := f.buf[:size]
@@ -1871,7 +1871,7 @@ func (f *framer) readBytes() []byte {
18711871
func (f *framer) readShortBytes() []byte {
18721872
size := f.readShort()
18731873
if len(f.buf) < int(size) {
1874-
panic(fmt.Errorf("not enough bytes in buffer to read short bytes: require %d got %d", size, len(f.buf)))
1874+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read short bytes: require %d got %d", size, len(f.buf)))
18751875
}
18761876

18771877
l := f.buf[:size]
@@ -1882,18 +1882,18 @@ func (f *framer) readShortBytes() []byte {
18821882

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

18881888
size := f.buf[0]
18891889
f.buf = f.buf[1:]
18901890

18911891
if !(size == 4 || size == 16) {
1892-
panic(fmt.Errorf("invalid IP size: %d", size))
1892+
panic(fmt.Errorf("gocql: invalid IP size: %d", size))
18931893
}
18941894

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

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