Skip to content

Commit 39044ba

Browse files
committed
server/failtracer: don't assume only being fed two-elem calls
This was overly specific before, and quickly failed when fail events had not been on of the right sort. Now, we're more lenient. These would happen, as in https://github.com/orgs/open-policy-agent/discussions/722#discussioncomment-14812737, when a fail event happened that's unrelated to unknowns lookup, but a valid failure nonetheless. So this will not lead to a hint. Only fail events of the previously-expected form could yield hints. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
1 parent f5eeb07 commit 39044ba

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

v1/server/failtracer/failtracer.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ func (b *failTracer) Hints(unknowns []ast.Ref) []Hint {
6969
var ref ast.Ref // when this is processed, only one input.X.Y ref is in the expression (SSA)
7070
switch {
7171
case expr.IsCall():
72-
for i := range 2 {
73-
op := expr.Operand(i)
72+
for _, op := range expr.Operands() {
7473
if r, ok := op.Value.(ast.Ref); ok && r.HasPrefix(ast.InputRootRef) {
7574
ref = r
7675
}

v1/server/failtracer/hints_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ func TestHints(t *testing.T) {
3838
{Message: "input.fruit.price undefined, did you mean input.fruits.price?"},
3939
},
4040
},
41+
{
42+
note: "failing function call",
43+
evts: []topdown.Event{
44+
evtFromExpr(`data.policy.udf(__local1__)`),
45+
},
46+
unknowns: []string{"input.fruits"},
47+
exp: nil,
48+
},
4149
{
4250
note: "all of input unknown, ignored",
4351
evts: []topdown.Event{

0 commit comments

Comments
 (0)