Skip to content

Commit 1e98f31

Browse files
committed
error messages were refactored
1 parent 34fdeeb commit 1e98f31

16 files changed

+107
-101
lines changed

cluster.go

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

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

conn.go

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

7575
func (p PasswordAuthenticator) Challenge(req []byte) ([]byte, Authenticator, error) {
7676
if !approve(string(req), p.AllowedAuthenticators) {
77-
return nil, nil, fmt.Errorf("unexpected authenticator %q", req)
77+
return nil, nil, fmt.Errorf("gocql: unexpected authenticator %q", req)
7878
}
7979
resp := make([]byte, 2+len(p.Username)+len(p.Password))
8080
resp[0] = 0
@@ -464,7 +464,7 @@ func (s *startupCoordinator) startup(ctx context.Context, supported map[string][
464464

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

470470
resp, challenger, err := s.conn.auth.Challenge([]byte(authFrame.class))
@@ -497,7 +497,7 @@ func (s *startupCoordinator) authenticateHandshake(ctx context.Context, authFram
497497
data: resp,
498498
}
499499
default:
500-
return fmt.Errorf("unknown frame response during authentication: %v", v)
500+
return fmt.Errorf("gocql: unknown frame response during authentication: %v", v)
501501
}
502502
}
503503
}
@@ -999,7 +999,7 @@ func (c *Conn) addCall(call *callReq) error {
999999
}
10001000
existingCall := c.calls[call.streamID]
10011001
if existingCall != nil {
1002-
return fmt.Errorf("attempting to use stream already in use: %d -> %d", call.streamID,
1002+
return fmt.Errorf("gocql: attempting to use stream already in use: %d -> %d", call.streamID,
10031003
existingCall.streamID)
10041004
}
10051005
c.calls[call.streamID] = call
@@ -1271,7 +1271,7 @@ func (c *Conn) prepareStatement(ctx context.Context, stmt string, tracer Tracer)
12711271
response: x.respMeta,
12721272
}
12731273
case error:
1274-
flight.err = x
1274+
flight.err = fmt.Errorf("cassandra: %w", x)
12751275
default:
12761276
flight.err = NewErrProtocol("Unknown type in response to prepare frame: %s", x)
12771277
}
@@ -1508,7 +1508,7 @@ func (c *Conn) UseKeyspace(keyspace string) error {
15081508
switch x := resp.(type) {
15091509
case *resultKeyspaceFrame:
15101510
case error:
1511-
return x
1511+
return fmt.Errorf("cassandra: %w", x)
15121512
default:
15131513
return NewErrProtocol("unknown frame in response to USE: %v", x)
15141514
}
@@ -1616,7 +1616,7 @@ func (c *Conn) executeBatch(ctx context.Context, batch *Batch) *Iter {
16161616

16171617
return iter
16181618
case error:
1619-
return &Iter{err: x, framer: framer}
1619+
return &Iter{err: fmt.Errorf("cassandra: %w", x), framer: framer}
16201620
default:
16211621
return &Iter{err: NewErrProtocol("Unknown type in response to batch statement: %s", x), framer: framer}
16221622
}

control.go

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

137137
// Filter to v4 addresses if any present
@@ -251,7 +251,7 @@ func (c *controlConn) connect(hosts []*HostInfo) error {
251251
conn = nil
252252
}
253253
if conn == nil {
254-
return fmt.Errorf("unable to connect to initial hosts: %v", err)
254+
return fmt.Errorf("gocql: unable to connect to initial hosts: %w", err)
255255
}
256256

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

280280
if c.session.cfg.filterHost(host) {
281-
return fmt.Errorf("host was filtered: %v", host.ConnectAddress())
281+
return fmt.Errorf("gocql: host was filtered: %v", host.ConnectAddress())
282282
}
283283

284284
if err := c.registerEvents(conn); err != nil {
285-
return fmt.Errorf("register events: %v", err)
285+
return fmt.Errorf("gocql: register events: %w", err)
286286
}
287287

288288
ch := &connHost{
@@ -332,7 +332,7 @@ func (c *controlConn) registerEvents(conn *Conn) error {
332332
if err != nil {
333333
return err
334334
} else if _, ok := frame.(*readyFrame); !ok {
335-
return fmt.Errorf("unexpected frame in response to register: got %T: %v\n", frame, frame)
335+
return fmt.Errorf("gocql: unexpected frame in response to register: got %T: %v\n", frame, frame)
336336
}
337337

338338
return nil
@@ -389,7 +389,7 @@ func (c *controlConn) attemptReconnect() (*Conn, error) {
389389
// changed their IPs while keeping the same hostname(s).
390390
initialHosts, resolvErr := addrsToHosts(c.session.cfg.Hosts, c.session.cfg.Port, c.session.logger)
391391
if resolvErr != nil {
392-
return nil, fmt.Errorf("resolve contact points' hostnames: %v", resolvErr)
392+
return nil, fmt.Errorf("gocql: resolve contact points' hostnames: %w", resolvErr)
393393
}
394394

395395
return c.attemptReconnectToAnyOfHosts(initialHosts)

dial.go

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

4242
if !validIpAddr(ip) {
43-
return nil, fmt.Errorf("host missing connect ip address: %v", ip)
43+
return nil, fmt.Errorf("gocql: host missing connect ip address: %v", ip)
4444
} else if port == 0 {
45-
return nil, fmt.Errorf("host missing port: %v", port)
45+
return nil, fmt.Errorf("gocql: host missing port: %v", port)
4646
}
4747

4848
connAddr := host.ConnectAddressAndPort()

filters.go

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

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

frame.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func (c *Consistency) UnmarshalText(text []byte) error {
234234
case "LOCAL_ONE":
235235
*c = LocalOne
236236
default:
237-
return fmt.Errorf("invalid consistency %q", string(text))
237+
return fmt.Errorf("gocql: invalid consistency %q", string(text))
238238
}
239239

240240
return nil
@@ -295,7 +295,7 @@ func (s *SerialConsistency) UnmarshalText(text []byte) error {
295295
case "LOCAL_SERIAL":
296296
*s = LocalSerial
297297
default:
298-
return fmt.Errorf("invalid consistency %q", string(text))
298+
return fmt.Errorf("gocql: invalid consistency %q", string(text))
299299
}
300300

301301
return nil
@@ -306,7 +306,7 @@ const (
306306
)
307307

308308
var (
309-
ErrFrameTooBig = errors.New("frame length is bigger than the maximum allowed")
309+
ErrFrameTooBig = errors.New("gocql: frame length is bigger than the maximum allowed")
310310
)
311311

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

450450
if version > protoVersion2 {
451451
if len(p) != 9 {
452-
return frameHeader{}, fmt.Errorf("not enough bytes to read header require 9 got: %d", len(p))
452+
return frameHeader{}, fmt.Errorf("gocql: not enough bytes to read header require 9 got: %d", len(p))
453453
}
454454

455455
head.stream = int(int16(p[2])<<8 | int16(p[3]))
456456
head.op = frameOp(p[4])
457457
head.length = int(readInt(p[5:]))
458458
} else {
459459
if len(p) != 8 {
460-
return frameHeader{}, fmt.Errorf("not enough bytes to read header require 8 got: %d", len(p))
460+
return frameHeader{}, fmt.Errorf("gocql: not enough bytes to read header require 8 got: %d", len(p))
461461
}
462462

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

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

512512
f.buf, err = f.compres.Decode(f.buf)
513513
if err != nil {
514-
return err
514+
return fmt.Errorf("gocql: %w", err)
515515
}
516516
}
517517

@@ -687,7 +687,7 @@ func (f *framer) parseErrorFrame() frame {
687687
// TODO(zariel): we should have some distinct types for these errors
688688
return errD
689689
default:
690-
panic(fmt.Errorf("unknown error code: 0x%x", errD.code))
690+
panic(fmt.Errorf("gocql: unknown error code: 0x%x", errD.code))
691691
}
692692
}
693693

@@ -756,7 +756,7 @@ func (f *framer) finish() error {
756756
// TODO: only compress frames which are big enough
757757
compressed, err := f.compres.Encode(f.buf[f.headSize:])
758758
if err != nil {
759-
return err
759+
return fmt.Errorf("gocql: %w", err)
760760
}
761761

762762
f.buf = append(f.buf[:f.headSize], compressed...)
@@ -836,7 +836,7 @@ func (w *writePrepareFrame) buildFrame(f *framer, streamID int) error {
836836
if f.proto > protoVersion4 {
837837
flags |= flagWithPreparedKeyspace
838838
} else {
839-
panic(fmt.Errorf("the keyspace can only be set with protocol 5 or higher"))
839+
panic(fmt.Errorf("gocql: the keyspace can only be set with protocol 5 or higher"))
840840
}
841841
}
842842
if f.proto > protoVersion4 {
@@ -935,7 +935,7 @@ func (f *framer) parsePreparedMetadata() preparedMetadata {
935935
meta.flags = f.readInt()
936936
meta.colCount = f.readInt()
937937
if meta.colCount < 0 {
938-
panic(fmt.Errorf("received negative column count: %d", meta.colCount))
938+
panic(fmt.Errorf("gocql: received negative column count: %d", meta.colCount))
939939
}
940940
meta.actualColCount = meta.colCount
941941

@@ -1032,7 +1032,7 @@ func (f *framer) parseResultMetadata() resultMetadata {
10321032
meta.flags = f.readInt()
10331033
meta.colCount = f.readInt()
10341034
if meta.colCount < 0 {
1035-
panic(fmt.Errorf("received negative column count: %d", meta.colCount))
1035+
panic(fmt.Errorf("gocql: received negative column count: %d", meta.colCount))
10361036
}
10371037
meta.actualColCount = meta.colCount
10381038

@@ -1119,7 +1119,7 @@ func (f *framer) parseResultRows() frame {
11191119

11201120
result.numRows = f.readInt()
11211121
if result.numRows < 0 {
1122-
panic(fmt.Errorf("invalid row_count in result frame: %d", result.numRows))
1122+
panic(fmt.Errorf("gocql: invalid row_count in result frame: %d", result.numRows))
11231123
}
11241124

11251125
return result
@@ -1487,7 +1487,7 @@ func (f *framer) writeQueryParams(opts *queryParams) {
14871487
if f.proto > protoVersion4 {
14881488
flags |= flagWithKeyspace
14891489
} else {
1490-
panic(fmt.Errorf("the keyspace can only be set with protocol 5 or higher"))
1490+
panic(fmt.Errorf("gocql: the keyspace can only be set with protocol 5 or higher"))
14911491
}
14921492
}
14931493

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

17511751
func (f *framer) readByte() byte {
17521752
if len(f.buf) < 1 {
1753-
panic(fmt.Errorf("not enough bytes in buffer to read byte require 1 got: %d", len(f.buf)))
1753+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read byte require 1 got: %d", len(f.buf)))
17541754
}
17551755

17561756
b := f.buf[0]
@@ -1760,7 +1760,7 @@ func (f *framer) readByte() byte {
17601760

17611761
func (f *framer) readInt() (n int) {
17621762
if len(f.buf) < 4 {
1763-
panic(fmt.Errorf("not enough bytes in buffer to read int require 4 got: %d", len(f.buf)))
1763+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read int require 4 got: %d", len(f.buf)))
17641764
}
17651765

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

17711771
func (f *framer) readShort() (n uint16) {
17721772
if len(f.buf) < 2 {
1773-
panic(fmt.Errorf("not enough bytes in buffer to read short require 2 got: %d", len(f.buf)))
1773+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read short require 2 got: %d", len(f.buf)))
17741774
}
17751775
n = uint16(f.buf[0])<<8 | uint16(f.buf[1])
17761776
f.buf = f.buf[2:]
@@ -1781,7 +1781,7 @@ func (f *framer) readString() (s string) {
17811781
size := f.readShort()
17821782

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

17871787
s = string(f.buf[:size])
@@ -1793,7 +1793,7 @@ func (f *framer) readLongString() (s string) {
17931793
size := f.readInt()
17941794

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

17991799
s = string(f.buf[:size])
@@ -1803,7 +1803,7 @@ func (f *framer) readLongString() (s string) {
18031803

18041804
func (f *framer) readUUID() *UUID {
18051805
if len(f.buf) < 16 {
1806-
panic(fmt.Errorf("not enough bytes in buffer to read uuid require %d got: %d", 16, len(f.buf)))
1806+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read uuid require %d got: %d", 16, len(f.buf)))
18071807
}
18081808

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

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

18361836
l := f.buf[:size]
@@ -1851,7 +1851,7 @@ func (f *framer) readBytes() []byte {
18511851
func (f *framer) readShortBytes() []byte {
18521852
size := f.readShort()
18531853
if len(f.buf) < int(size) {
1854-
panic(fmt.Errorf("not enough bytes in buffer to read short bytes: require %d got %d", size, len(f.buf)))
1854+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read short bytes: require %d got %d", size, len(f.buf)))
18551855
}
18561856

18571857
l := f.buf[:size]
@@ -1862,18 +1862,18 @@ func (f *framer) readShortBytes() []byte {
18621862

18631863
func (f *framer) readInetAdressOnly() net.IP {
18641864
if len(f.buf) < 1 {
1865-
panic(fmt.Errorf("not enough bytes in buffer to read inet size require %d got: %d", 1, len(f.buf)))
1865+
panic(fmt.Errorf("gocql: not enough bytes in buffer to read inet size require %d got: %d", 1, len(f.buf)))
18661866
}
18671867

18681868
size := f.buf[0]
18691869
f.buf = f.buf[1:]
18701870

18711871
if !(size == 4 || size == 16) {
1872-
panic(fmt.Errorf("invalid IP size: %d", size))
1872+
panic(fmt.Errorf("gocql: invalid IP size: %d", size))
18731873
}
18741874

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

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

helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func goType(t TypeInfo) (reflect.Type, error) {
7777
case TypeDuration:
7878
return reflect.TypeOf(*new(Duration)), nil
7979
default:
80-
return nil, fmt.Errorf("cannot create Go type for unknown CQL type %s", t)
80+
return nil, fmt.Errorf("gocql: cannot create Go type for unknown CQL type %s", t)
8181
}
8282
}
8383

0 commit comments

Comments
 (0)