Also return an error from nvcdi.New

This change allows nvcdi.New to return an error in addition to the
constructed library instead of panicing.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar
2023-03-22 14:04:12 +02:00
parent 1ebbebf5de
commit 226c54613e
4 changed files with 13 additions and 7 deletions

View File

@@ -49,7 +49,7 @@ type nvcdilib struct {
}
// New creates a new nvcdi library
func New(opts ...Option) Interface {
func New(opts ...Option) (Interface, error) {
l := &nvcdilib{}
for _, opt := range opts {
opt(l)
@@ -102,8 +102,7 @@ func New(opts ...Option) Interface {
}
lib = (*mofedlib)(l)
default:
// TODO: We would like to return an error here instead of panicking
panic("Unknown mode")
return nil, fmt.Errorf("unknown mode %q", l.mode)
}
w := wrapper{
@@ -111,7 +110,7 @@ func New(opts ...Option) Interface {
vendor: l.vendor,
class: l.class,
}
return &w
return &w, nil
}
// GetSpec combines the device specs and common edits from the wrapped Interface to a single spec.Interface.