Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/cache/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cache

import (
"iter"
"reflect"

"github.com/gravitational/trace"

Expand Down Expand Up @@ -77,7 +78,7 @@ func (s *store[T, I]) len() int {
func (s *store[T, I]) get(index I, key string) (T, error) {
t, ok := s.cache.Get(index, key)
if !ok {
return t, trace.NotFound("no value for key %q in index %v", key, index)
return t, trace.NotFound("%v %q does not exist", reflect.TypeFor[T](), key)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this error user facing? Can we get to a resource kind string somehow?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could very well be returned to the user. I can likely restrict T to an interface that implements GetKind.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's going to be annoying for 153-style resources - is that better or worse than just requiring a user-friendly name for error messages in store?

...also, we're hitting this error message because failed to find the T, and almost all of our resources don't have a "static" GetKind method, they read the kind from the value. 😬

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably less viable than adding a user friendly identifier, though, it will require more boilerplate to stuff in the appropriate string to each resource stores.

}

return t, nil
Expand Down
6 changes: 3 additions & 3 deletions lib/cache/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestResourceStore(t *testing.T) {
require.Equal(t, 0, zero)

n, err := store.get("numbers", "1000")
require.ErrorIs(t, err, &trace.NotFoundError{Message: `no value for key "1000" in index numbers`})
require.ErrorIs(t, err, &trace.NotFoundError{Message: `int "1000" does not exist`})
require.Equal(t, 0, n)

v, err := store.get("characters", "1c")
Expand All @@ -58,12 +58,12 @@ func TestResourceStore(t *testing.T) {

require.NoError(t, store.delete(0))
_, err = store.get("numbers", "0")
require.ErrorIs(t, err, &trace.NotFoundError{Message: `no value for key "0" in index numbers`})
require.ErrorIs(t, err, &trace.NotFoundError{Message: `int "0" does not exist`})

require.NoError(t, store.clear())

_, err = store.get("numbers", "0")
require.ErrorIs(t, err, &trace.NotFoundError{Message: `no value for key "0" in index numbers`})
require.ErrorIs(t, err, &trace.NotFoundError{Message: `int "0" does not exist`})

require.Zero(t, store.len())
}
Loading