diff --git a/storage/storage.go b/storage/storage.go index 6124f2b687..d8c923ccae 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -179,7 +179,7 @@ func (s *Storage) Read(txn Transaction, path ast.Ref) (interface{}, error) { } if !path.IsGround() { - return nil, internalError("non-ground reference:", path) + return nil, internalError("non-ground reference: %v", path) } holes := []hole{} diff --git a/storage/storage_test.go b/storage/storage_test.go index 29862ef932..e91fa883ac 100644 --- a/storage/storage_test.go +++ b/storage/storage_test.go @@ -12,6 +12,21 @@ import ( "github.com/open-policy-agent/opa/ast" ) +func TestStorageReadNonGroundRef(t *testing.T) { + store := New(InMemoryConfig()) + txn := NewTransactionOrDie(store) + defer store.Close(txn) + ref := ast.MustParseRef("data.foo[i]") + _, e := store.Read(txn, ref) + err, ok := e.(*Error) + if !ok { + t.Fatalf("Expected storage error but got: %v", err) + } + if err.Code != InternalErr { + t.Fatalf("Expected internal error but got: %v", err) + } +} + func TestStorageReadPlugin(t *testing.T) { mem1 := NewDataStoreFromReader(strings.NewReader(`