1717package cdi
1818
1919import (
20+ "errors"
21+ "fmt"
2022 "io/fs"
2123 "os"
2224 "path/filepath"
2325 "sort"
2426 "strings"
2527 "sync"
2628
27- stderr "errors"
28-
2929 "github.com/container-orchestrated-devices/container-device-interface/internal/multierror"
3030 cdi "github.com/container-orchestrated-devices/container-device-interface/specs-go"
3131 "github.com/fsnotify/fsnotify"
3232 oci "github.com/opencontainers/runtime-spec/specs-go"
33- "github.com/pkg/errors"
3433)
3534
3635// Option is an option to change some aspect of default CDI behavior.
@@ -97,7 +96,7 @@ func (c *Cache) configure(options ...Option) error {
9796
9897 for _ , o := range options {
9998 if err = o (c ); err != nil {
100- return errors . Wrapf ( err , "failed to apply cache options" )
99+ return fmt . Errorf ( "failed to apply cache options: %w" , err )
101100 }
102101 }
103102
@@ -159,7 +158,7 @@ func (c *Cache) refresh() error {
159158 return false
160159 case devPrio == oldPrio :
161160 devPath , oldPath := devSpec .GetPath (), oldSpec .GetPath ()
162- collectError (errors .Errorf ("conflicting device %q (specs %q, %q)" ,
161+ collectError (fmt .Errorf ("conflicting device %q (specs %q, %q)" ,
163162 name , devPath , oldPath ), devPath , oldPath )
164163 conflicts [name ] = struct {}{}
165164 }
@@ -169,7 +168,7 @@ func (c *Cache) refresh() error {
169168 _ = scanSpecDirs (c .specDirs , func (path string , priority int , spec * Spec , err error ) error {
170169 path = filepath .Clean (path )
171170 if err != nil {
172- collectError (errors . Wrapf ( err , "failed to load CDI Spec" ), path )
171+ collectError (fmt . Errorf ( "failed to load CDI Spec %w" , err ), path )
173172 return nil
174173 }
175174
@@ -219,7 +218,7 @@ func (c *Cache) InjectDevices(ociSpec *oci.Spec, devices ...string) ([]string, e
219218 var unresolved []string
220219
221220 if ociSpec == nil {
222- return devices , errors .Errorf ("can't inject devices, nil OCI Spec" )
221+ return devices , fmt .Errorf ("can't inject devices, nil OCI Spec" )
223222 }
224223
225224 c .Lock ()
@@ -244,12 +243,12 @@ func (c *Cache) InjectDevices(ociSpec *oci.Spec, devices ...string) ([]string, e
244243 }
245244
246245 if unresolved != nil {
247- return unresolved , errors .Errorf ("unresolvable CDI devices %s" ,
246+ return unresolved , fmt .Errorf ("unresolvable CDI devices %s" ,
248247 strings .Join (devices , ", " ))
249248 }
250249
251250 if err := edits .Apply (ociSpec ); err != nil {
252- return nil , errors . Wrap ( err , "failed to inject devices" )
251+ return nil , fmt . Errorf ( "failed to inject devices: %w" , err )
253252 }
254253
255254 return nil , nil
@@ -320,7 +319,7 @@ func (c *Cache) RemoveSpec(name string) error {
320319 }
321320
322321 err = os .Remove (path )
323- if err != nil && stderr .Is (err , fs .ErrNotExist ) {
322+ if err != nil && errors .Is (err , fs .ErrNotExist ) {
324323 err = nil
325324 }
326325
@@ -485,7 +484,7 @@ func (w *watch) setup(dirs []string, dirErrors map[string]error) {
485484 w .watcher , err = fsnotify .NewWatcher ()
486485 if err != nil {
487486 for _ , dir := range dirs {
488- dirErrors [dir ] = errors . Wrap ( err , "failed to create watcher" )
487+ dirErrors [dir ] = fmt . Errorf ( "failed to create watcher: %w" , err )
489488 }
490489 return
491490 }
@@ -568,7 +567,7 @@ func (w *watch) update(dirErrors map[string]error, removed ...string) bool {
568567 update = true
569568 } else {
570569 w .tracked [dir ] = false
571- dirErrors [dir ] = errors . Wrap ( err , "failed to monitor for changes" )
570+ dirErrors [dir ] = fmt . Errorf ( "failed to monitor for changes: %w" , err )
572571 }
573572 }
574573
0 commit comments