Return a wrapped fs.ErrNotExist if no spec directories are defined#309
Return a wrapped fs.ErrNotExist if no spec directories are defined#309elezar wants to merge 1 commit intocncf-tags:mainfrom
Conversation
|
Thanks @klihub. While working on this, I was wondering whether we want to more strictly define (i.e. return an error from |
Yeah, at least my gut feeling is that it sounds like a reasonable idea. Another option would be to update and document the |
I think this is a cleaner solution. Created #310 to do this. |
2026e9b to
bb2fc73
Compare
|
rebased. |
| specDir, _ = c.highestPrioritySpecDir() | ||
| if specDir == "" { | ||
| return errors.New("no Spec directories to remove from") | ||
| return fmt.Errorf("no Spec directories defined: %w", fs.ErrNotExist) |
There was a problem hiding this comment.
the fix looks good to me, but how about adding test case for this?
err := cache.RemoveSpec("something")
assert.True(t, errors.Is(err, fs.ErrNotExist))There was a problem hiding this comment.
I have added a basic test.
There was a problem hiding this comment.
@klihub as also pointed out by the test, we do have a slight disconnect here. In the case where the spec dirs are empty, we return ErrNotExist, but in the case where os.Remove fails for the spec we are trying to remove due to ErrNotExist we return nil. Should we always return nil (or ErrNotExist) for consistency?
| @@ -321,7 +321,7 @@ func (c *Cache) RemoveSpec(name string) error { | |||
|
|
|||
| specDir, _ = c.highestPrioritySpecDir() | |||
| if specDir == "" { | |||
There was a problem hiding this comment.
It shouldn't be possible, no.
There was a problem hiding this comment.
Does that mean we want to update the highestPrioritySpecDir implementation to not return an error?
There was a problem hiding this comment.
I think it does not return an error. It returns a directory and its priority.
Signed-off-by: Evan Lezar <elezar@nvidia.com>
bb2fc73 to
092f1f9
Compare
See the discussion here: #308 (comment)
Here we return a wrapped
fs.ErrNotExisterror if there are no spec directories defined instead of a raw error that cannot be queried easily by the caller.