Selaa lähdekoodia

improve create session and control connection dial errors

Chris Bannister 9 vuotta sitten
vanhempi
commit
df9c036fe4
2 muutettua tiedostoa jossa 6 lisäystä ja 6 poistoa
  1. 4 4
      control.go
  2. 2 2
      session.go

+ 4 - 4
control.go

@@ -104,7 +104,7 @@ func (c *controlConn) shuffleDial(endpoints []string) (conn *Conn, err error) {
 			return
 		}
 
-		log.Printf("gocql: unable to control conn dial %v: %v\n", addr, err)
+		log.Printf("gocql: unable to dial control conn %v: %v\n", addr, err)
 	}
 
 	return
@@ -113,14 +113,14 @@ func (c *controlConn) shuffleDial(endpoints []string) (conn *Conn, err error) {
 func (c *controlConn) connect(endpoints []string) error {
 	conn, err := c.shuffleDial(endpoints)
 	if err != nil {
-		return err
+		return fmt.Errorf("control: unable to connect: %v", err)
 	} else if conn == nil {
-		return errors.New("gocql: unable to connect to initial endpoints")
+		return errors.New("control: unable to connect to initial endpoints")
 	}
 
 	if err := c.setupConn(conn); err != nil {
 		conn.Close()
-		return err
+		return fmt.Errorf("control: unable to setup connection: %v", err)
 	}
 
 	// we could fetch the initial ring here and update initial host data. So that

+ 2 - 2
session.go

@@ -122,7 +122,7 @@ func NewSession(cfg ClusterConfig) (*Session, error) {
 		s.control = createControlConn(s)
 		if err := s.control.connect(cfg.Hosts); err != nil {
 			s.Close()
-			return nil, err
+			return nil, fmt.Errorf("gocql: unable to create session: %v", err)
 		}
 
 		// need to setup host source to check for broadcast_address in system.local
@@ -140,7 +140,7 @@ func NewSession(cfg ClusterConfig) (*Session, error) {
 
 		if err != nil {
 			s.Close()
-			return nil, err
+			return nil, fmt.Errorf("gocql: unable to create session: %v", err)
 		}
 	} else {
 		// we dont get host info