Skip to content

Return a wrapped fs.ErrNotExist if no spec directories are defined#309

Open
elezar wants to merge 1 commit intocncf-tags:mainfrom
elezar:return-fs-err-no-exits
Open

Return a wrapped fs.ErrNotExist if no spec directories are defined#309
elezar wants to merge 1 commit intocncf-tags:mainfrom
elezar:return-fs-err-no-exits

Conversation

@elezar
Copy link
Contributor

@elezar elezar commented Feb 19, 2026

See the discussion here: #308 (comment)

Here we return a wrapped fs.ErrNotExist error if there are no spec directories defined instead of a raw error that cannot be queried easily by the caller.

@elezar
Copy link
Contributor Author

elezar commented Feb 20, 2026

Thanks @klihub. While working on this, I was wondering whether we want to more strictly define (i.e. return an error from Configure) when no spec directories are defined? With that said, maybe this is a way for a user to instantiate an in-memory cache, but I would rather make that explicit rather than implicit.

@klihub
Copy link
Contributor

klihub commented Feb 20, 2026

Thanks @klihub. While working on this, I was wondering whether we want to more strictly define (i.e. return an error from Configure) when no spec directories are defined?

Yeah, at least my gut feeling is that it sounds like a reasonable idea.

Another option would be to update and document the cdi.WithSpecDirs option to ignore an empty director list and instead run with the defaults... since IFAICT using an explicit cdi.WithSpecDirs() is the only way how you can end up in this situation.

@elezar
Copy link
Contributor Author

elezar commented Feb 20, 2026

Another option would be to update and document the cdi.WithSpecDirs option to ignore an empty director list and instead run with the defaults... since IFAICT using an explicit cdi.WithSpecDirs() is the only way how you can end up in this situation.

I think this is a cleaner solution. Created #310 to do this.

@elezar elezar marked this pull request as draft February 20, 2026 13:32
@elezar elezar force-pushed the return-fs-err-no-exits branch from 2026e9b to bb2fc73 Compare February 20, 2026 13:32
@elezar
Copy link
Contributor Author

elezar commented Feb 20, 2026

rebased.

@elezar elezar marked this pull request as ready for review February 20, 2026 13:33
specDir, _ = c.highestPrioritySpecDir()
if specDir == "" {
return errors.New("no Spec directories to remove from")
return fmt.Errorf("no Spec directories defined: %w", fs.ErrNotExist)
Copy link
Contributor

Choose a reason for hiding this comment

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

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))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added a basic test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@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?

@klihub klihub self-requested a review February 23, 2026 16:47
@@ -321,7 +321,7 @@ func (c *Cache) RemoveSpec(name string) error {

specDir, _ = c.highestPrioritySpecDir()
if specDir == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

@elezar Can this still happen with #310 merged ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't be possible, no.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does that mean we want to update the highestPrioritySpecDir implementation to not return an error?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it does not return an error. It returns a directory and its priority.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
@elezar elezar force-pushed the return-fs-err-no-exits branch from bb2fc73 to 092f1f9 Compare March 4, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants