Skip to content

Commit aa9157b

Browse files
committed
misc review comments
Signed-off-by: Stephan Renatus <[email protected]>
1 parent c150414 commit aa9157b

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

v1/rego/compile/compile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (c *Compile) timer(t string) minimetrics {
175175
return n
176176
}
177177

178-
// Prepare evaluates as much as possible without known the (known) input yet
178+
// Prepare evaluates as much as possible without knowing the (known) input yet
179179
func (c *Compile) Prepare(ctx context.Context, po ...PrepareOption) (*Prepared, error) {
180180
p := &Prepared{
181181
compile: c,

v1/server/failtracer/failtracer.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ func (b *failTracer) Hints(unknowns []*ast.Term) []Hint {
5959
seenRefs := map[string]struct{}{}
6060
candidates := make([]string, 0, len(unknowns))
6161
for i := range unknowns {
62+
ref, ok := unknowns[i].Value.(ast.Ref)
63+
if !ok || len(ref) < 2 {
64+
continue
65+
}
6266
candidates = append(candidates, string(unknowns[i].Value.(ast.Ref)[1].Value.(ast.String)))
6367
}
6468

@@ -91,13 +95,11 @@ func (b *failTracer) Hints(unknowns []*ast.Term) []Hint {
9195
closestStrings := levenshtein.ClosestStrings(maxDistanceForHint, miss, slices.Values(candidates))
9296
proposals := make([]ast.Ref, len(closestStrings))
9397
for i := range closestStrings {
94-
if len(ref) >= 1 {
95-
prop := make([]*ast.Term, 2, len(ref))
96-
prop[0] = ast.InputRootDocument
97-
prop[1] = ast.StringTerm(closestStrings[i])
98-
prop = append(prop, ref[2:]...)
99-
proposals[i] = prop
100-
}
98+
prop := make([]*ast.Term, 2, len(ref))
99+
prop[0] = ast.InputRootDocument
100+
prop[1] = ast.StringTerm(closestStrings[i])
101+
prop = append(prop, ref[2:]...)
102+
proposals[i] = prop
101103
}
102104
var msg string
103105
switch len(proposals) {

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: "all of input unknown, ignored",
43+
evts: []topdown.Event{
44+
evtFromExpr(`__local1__ = input.fruit.price`),
45+
},
46+
unknowns: []string{"input"},
47+
exp: nil,
48+
},
4149
{
4250
note: "simple typo, short ref",
4351
evts: []topdown.Event{

v1/server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ func getRevisions(ctx context.Context, store storage.Store, txn storage.Transact
10501050
return br, nil
10511051
}
10521052

1053-
func (s *Server) reload(ctx context.Context, txn storage.Transaction, evt storage.TriggerEvent) {
1053+
func (s *Server) reload(_ context.Context, _ storage.Transaction, evt storage.TriggerEvent) {
10541054
// NOTE(tsandall): We currently rely on the storage txn to provide
10551055
// critical sections in the server.
10561056
//

0 commit comments

Comments
 (0)