Skip to content

Commit 654a63d

Browse files
authored
Merge pull request #571 from erizocosmico/fix/uast-errors
function: log bblfsh errors on UAST instead of returning them
2 parents 21eb9b4 + cf505ed commit 654a63d

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

internal/function/uast.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"sync"
1111

1212
lru "github.com/hashicorp/golang-lru"
13+
"github.com/sirupsen/logrus"
1314
bblfsh "gopkg.in/bblfsh/client-go.v3"
1415
"gopkg.in/bblfsh/sdk.v2/uast"
1516
"gopkg.in/bblfsh/sdk.v2/uast/nodes"
@@ -206,7 +207,8 @@ func (u *uastFunc) getUAST(
206207
return nil, nil
207208
}
208209

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

212214
uastCache.Add(key, node)
@@ -219,11 +221,20 @@ func (u *uastFunc) getUAST(
219221
var err error
220222
nodeArray, err = applyXpath(node, xpath)
221223
if err != nil {
222-
return nil, err
224+
logrus.WithField("err", err).
225+
Errorf("unable to filter node using xpath: %s", xpath)
226+
return nil, nil
223227
}
224228
}
225229

226-
return marshalNodes(nodeArray)
230+
result, err := marshalNodes(nodeArray)
231+
if err != nil {
232+
logrus.WithField("err", err).
233+
Error("unable to marshal UAST nodes")
234+
return nil, nil
235+
}
236+
237+
return result, nil
227238
}
228239

229240
// UAST returns an array of UAST nodes as blobs.

internal/function/uast_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func TestUASTChildren(t *testing.T) {
238238
{
239239
mode: "semantic",
240240
key: uast.KeyType,
241-
expected: []string{"uast:FunctionGroup", "Expr"},
241+
expected: []string{"uast:FunctionGroup", "python:Expr"},
242242
},
243243
{
244244
mode: "annotated",

internal/function/uast_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ func marshalNodes(arr nodes.Array) (interface{}, error) {
140140
return nil, nil
141141
}
142142

143-
buf := &bytes.Buffer{}
144-
if err := nodesproto.WriteTo(buf, arr); err != nil {
143+
var buf bytes.Buffer
144+
if err := nodesproto.WriteTo(&buf, arr); err != nil {
145145
return nil, err
146146
}
147147

0 commit comments

Comments
 (0)