-
Notifications
You must be signed in to change notification settings - Fork 42
pkg/cdi: add missing error checks in cache #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,9 @@ func NewCache(options ...Option) (*Cache, error) { | |
watch: &watch{}, | ||
} | ||
|
||
WithSpecDirs(DefaultSpecDirs...)(c) | ||
if err := WithSpecDirs(DefaultSpecDirs...)(c); err != nil { | ||
return nil, err | ||
} | ||
c.Lock() | ||
defer c.Unlock() | ||
|
||
|
@@ -107,9 +109,7 @@ func (c *Cache) configure(options ...Option) error { | |
c.watch.setup(c.specDirs, c.dirErrors) | ||
c.watch.start(&c.Mutex, c.refresh, c.dirErrors) | ||
} | ||
c.refresh() | ||
|
||
return nil | ||
return c.refresh() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBH, off the top of my head I'm not sure if this could cause problems. Looking at the code, maybe it would be better/simpler/cleaner to change the API so that [Rr]efresh() never returns an error. Since errors encountered during the last refresh can anyway be queried using GetErrors(), if a caller is interested in errors it can query them itself. |
||
} | ||
|
||
// Refresh rescans the CDI Spec directories and refreshes the Cache. | ||
|
@@ -224,7 +224,7 @@ func (c *Cache) InjectDevices(ociSpec *oci.Spec, devices ...string) ([]string, e | |
c.Lock() | ||
defer c.Unlock() | ||
|
||
c.refreshIfRequired(false) | ||
_, _ = c.refreshIfRequired(false) | ||
|
||
edits := &ContainerEdits{} | ||
specs := map[*Spec]struct{}{} | ||
|
@@ -331,7 +331,7 @@ func (c *Cache) GetDevice(device string) *Device { | |
c.Lock() | ||
defer c.Unlock() | ||
|
||
c.refreshIfRequired(false) | ||
_, _ = c.refreshIfRequired(false) | ||
|
||
return c.devices[device] | ||
} | ||
|
@@ -343,7 +343,7 @@ func (c *Cache) ListDevices() []string { | |
c.Lock() | ||
defer c.Unlock() | ||
|
||
c.refreshIfRequired(false) | ||
_, _ = c.refreshIfRequired(false) | ||
|
||
for name := range c.devices { | ||
devices = append(devices, name) | ||
|
@@ -360,7 +360,7 @@ func (c *Cache) ListVendors() []string { | |
c.Lock() | ||
defer c.Unlock() | ||
|
||
c.refreshIfRequired(false) | ||
_, _ = c.refreshIfRequired(false) | ||
|
||
for vendor := range c.specs { | ||
vendors = append(vendors, vendor) | ||
|
@@ -380,7 +380,7 @@ func (c *Cache) ListClasses() []string { | |
c.Lock() | ||
defer c.Unlock() | ||
|
||
c.refreshIfRequired(false) | ||
_, _ = c.refreshIfRequired(false) | ||
|
||
for _, specs := range c.specs { | ||
for _, spec := range specs { | ||
|
@@ -400,7 +400,7 @@ func (c *Cache) GetVendorSpecs(vendor string) []*Spec { | |
c.Lock() | ||
defer c.Unlock() | ||
|
||
c.refreshIfRequired(false) | ||
_, _ = c.refreshIfRequired(false) | ||
|
||
return c.specs[vendor] | ||
} | ||
|
@@ -535,7 +535,7 @@ func (w *watch) watch(fsw *fsnotify.Watcher, m *sync.Mutex, refresh func() error | |
} else { | ||
w.update(dirErrors) | ||
} | ||
refresh() | ||
_ = refresh() | ||
m.Unlock() | ||
|
||
case _, ok := <-watch.Errors: | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WithSpecDirs
is anOption
which can't fail, so this is definitely a behavior-unaltering change and as such definitely fine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, ok, this lead me to submit #187 (replaces this particular change)