From d713638d8cff6b6b4e7c69397b00b7a641e765c7 Mon Sep 17 00:00:00 2001 From: Torin Sandall Date: Wed, 26 Oct 2016 10:13:49 -0700 Subject: [PATCH] Fix string formatting on storage error --- storage/storage.go | 2 +- storage/storage_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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(`