@@ -143,7 +143,7 @@ func (s *Session) BblfshClient() (*BblfshClient, error) {
143143 defer s .bblfshMu .Unlock ()
144144
145145 if s .bblfshClient == nil {
146- client , err := bblfsh . NewClient (s .bblfshEndpoint )
146+ client , err := connectToBblfsh (s .bblfshEndpoint )
147147 if err != nil {
148148 return nil , err
149149 }
@@ -172,7 +172,7 @@ func (s *Session) BblfshClient() (*BblfshClient, error) {
172172
173173 logrus .Debug ("bblfsh connection is closed, opening a new one" )
174174
175- client , err := bblfsh . NewClient (s .bblfshEndpoint )
175+ client , err := connectToBblfsh (s .bblfshEndpoint )
176176 if err != nil {
177177 return nil , err
178178 }
@@ -196,6 +196,19 @@ func (s *Session) Close() error {
196196 return nil
197197}
198198
199+ func connectToBblfsh (endpoint string ) (* bblfsh.Client , error ) {
200+ client , err := bblfsh .NewClient (endpoint )
201+ if err != nil {
202+ if err == context .DeadlineExceeded {
203+ return nil , ErrBblfshConnection .New ()
204+ }
205+
206+ return nil , err
207+ }
208+
209+ return client , nil
210+ }
211+
199212// NewSessionBuilder creates a SessionBuilder with the given Repository Pool.
200213func NewSessionBuilder (pool * RepositoryPool , opts ... SessionOption ) server.SessionBuilder {
201214 return func (_ * mysql.Conn ) sql.Session {
@@ -215,4 +228,4 @@ var ErrInvalidGitbaseSession = errors.NewKind("expecting gitbase session, but re
215228var ErrInvalidContext = errors .NewKind ("invalid context received: %v" )
216229
217230// ErrBblfshConnection is returned when it's impossible to connect to bblfsh.
218- var ErrBblfshConnection = errors .NewKind ("unable to establish a new bblfsh connection " )
231+ var ErrBblfshConnection = errors .NewKind ("unable to establish a connection with the bblfsh server " )
0 commit comments