Skip to content

Commit 2dbc45e

Browse files
authored
Merge pull request #612 from erizocosmico/feature/uast-errors
*: make UAST functions fail on connection errors
2 parents 51bdd0f + c4a44b5 commit 2dbc45e

File tree

39 files changed

+886
-2299
lines changed

39 files changed

+886
-2299
lines changed

Gopkg.lock

Lines changed: 8 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@
5454

5555
[[constraint]]
5656
name = "gopkg.in/bblfsh/client-go.v3"
57-
version = "3.0.0"
57+
version = "3.1.0"
5858

5959
[[override]]
6060
name = "gopkg.in/bblfsh/sdk.v1"
6161
version = "1.16.0"
6262

6363
[[constraint]]
6464
name = "gopkg.in/bblfsh/sdk.v2"
65-
version = "2.3.0"
65+
version = "2.7.0"
6666

6767
[[constraint]]
6868
name = "github.com/uber/jaeger-client-go"

internal/function/uast.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
lru "github.com/hashicorp/golang-lru"
1313
"github.com/sirupsen/logrus"
1414
bblfsh "gopkg.in/bblfsh/client-go.v3"
15+
derrors "gopkg.in/bblfsh/sdk.v2/driver/errors"
1516
"gopkg.in/bblfsh/sdk.v2/uast"
1617
"gopkg.in/bblfsh/sdk.v2/uast/nodes"
1718

@@ -203,12 +204,11 @@ func (u *uastFunc) getUAST(
203204
var err error
204205
node, err = getUASTFromBblfsh(ctx, blob, lang, xpath, mode)
205206
if err != nil {
206-
if ErrParseBlob.Is(err) {
207+
if ErrParseBlob.Is(err) || derrors.ErrSyntax.Is(err) {
207208
return nil, nil
208209
}
209210

210-
logrus.WithField("err", err).Error("unable to get UAST from bblfsh")
211-
return nil, nil
211+
return nil, err
212212
}
213213

214214
uastCache.Add(key, node)

session.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (s *Session) BblfshClient() (*BblfshClient, error) {
177177
var attempts, totalAttempts int
178178
for {
179179
if attempts > bblfshMaxAttempts || totalAttempts > 3*bblfshMaxAttempts {
180-
return nil, ErrBblfshConnection.New()
180+
return nil, ErrBblfshConnection.New("max attempts exceeded")
181181
}
182182

183183
switch s.bblfshClient.GetState() {
@@ -190,7 +190,7 @@ func (s *Session) BblfshClient() (*BblfshClient, error) {
190190
time.Sleep(100 * time.Millisecond)
191191
default:
192192
if err := s.bblfshClient.Close(); err != nil {
193-
return nil, err
193+
return nil, ErrBblfshConnection.New(err)
194194
}
195195

196196
logrus.Debug("bblfsh connection is closed, opening a new one")
@@ -223,10 +223,10 @@ func connectToBblfsh(endpoint string) (*bblfsh.Client, error) {
223223
client, err := bblfsh.NewClient(endpoint)
224224
if err != nil {
225225
if err == context.DeadlineExceeded {
226-
return nil, ErrBblfshConnection.New()
226+
return nil, ErrBblfshConnection.New(err)
227227
}
228228

229-
return nil, err
229+
return nil, ErrBblfshConnection.New(err)
230230
}
231231

232232
return client, nil
@@ -252,7 +252,7 @@ var ErrInvalidGitbaseSession = errors.NewKind("expecting gitbase session, but re
252252
var ErrInvalidContext = errors.NewKind("invalid context received: %v")
253253

254254
// ErrBblfshConnection is returned when it's impossible to connect to bblfsh.
255-
var ErrBblfshConnection = errors.NewKind("unable to establish a connection with the bblfsh server")
255+
var ErrBblfshConnection = errors.NewKind("unable to establish a connection with the bblfsh server: %s")
256256

257257
func shouldSkipErrors(ctx *sql.Context) bool {
258258
s, err := getSession(ctx)

vendor/github.com/golang/glog/LICENSE

Lines changed: 0 additions & 191 deletions
This file was deleted.

vendor/github.com/golang/glog/README

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)