|
@@ -126,16 +126,24 @@ func NewSession(cfg ClusterConfig) (*Session, error) {
|
|
|
policy: cfg.PoolConfig.HostSelectionPolicy,
|
|
policy: cfg.PoolConfig.HostSelectionPolicy,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if err := s.init(); err != nil {
|
|
|
|
|
- // TODO(zariel): dont wrap this error in fmt.Errorf, return a typed error
|
|
|
|
|
- s.Close()
|
|
|
|
|
|
|
+ //Check the TLS Config before trying to connect to anything external
|
|
|
|
|
+ connCfg, err := connConfig(&s.cfg)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ //TODO: Return a typed error
|
|
|
return nil, fmt.Errorf("gocql: unable to create session: %v", err)
|
|
return nil, fmt.Errorf("gocql: unable to create session: %v", err)
|
|
|
}
|
|
}
|
|
|
|
|
+ s.connCfg = connCfg
|
|
|
|
|
|
|
|
- if s.pool.Size() == 0 {
|
|
|
|
|
- // TODO(zariel): move this to init
|
|
|
|
|
|
|
+ if err := s.init(); err != nil {
|
|
|
s.Close()
|
|
s.Close()
|
|
|
- return nil, ErrNoConnectionsStarted
|
|
|
|
|
|
|
+ if err == ErrNoConnectionsStarted {
|
|
|
|
|
+ //This error used to be generated inside NewSession & returned directly
|
|
|
|
|
+ //Forward it on up to be backwards compatible
|
|
|
|
|
+ return nil, ErrNoConnectionsStarted
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // TODO(zariel): dont wrap this error in fmt.Errorf, return a typed error
|
|
|
|
|
+ return nil, fmt.Errorf("gocql: unable to create session: %v", err)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return s, nil
|
|
return s, nil
|
|
@@ -147,12 +155,6 @@ func (s *Session) init() error {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- connCfg, err := connConfig(s)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return err
|
|
|
|
|
- }
|
|
|
|
|
- s.connCfg = connCfg
|
|
|
|
|
-
|
|
|
|
|
if !s.cfg.disableControlConn {
|
|
if !s.cfg.disableControlConn {
|
|
|
s.control = createControlConn(s)
|
|
s.control = createControlConn(s)
|
|
|
if s.cfg.ProtoVersion == 0 {
|
|
if s.cfg.ProtoVersion == 0 {
|
|
@@ -165,7 +167,7 @@ func (s *Session) init() error {
|
|
|
|
|
|
|
|
// TODO(zariel): we really only need this in 1 place
|
|
// TODO(zariel): we really only need this in 1 place
|
|
|
s.cfg.ProtoVersion = proto
|
|
s.cfg.ProtoVersion = proto
|
|
|
- connCfg.ProtoVersion = proto
|
|
|
|
|
|
|
+ s.connCfg.ProtoVersion = proto
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if err := s.control.connect(hosts); err != nil {
|
|
if err := s.control.connect(hosts); err != nil {
|
|
@@ -212,6 +214,10 @@ func (s *Session) init() error {
|
|
|
s.useSystemSchema = hosts[0].Version().Major >= 3
|
|
s.useSystemSchema = hosts[0].Version().Major >= 3
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if s.pool.Size() == 0 {
|
|
|
|
|
+ return ErrNoConnectionsStarted
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|