mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 08:18:32 +00:00
Check returned error values
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
e0df157f70
commit
8a9f367067
@ -119,10 +119,10 @@ func run(c *cli.Context, opts *options) error {
|
|||||||
}
|
}
|
||||||
defer output.Close()
|
defer output.Close()
|
||||||
|
|
||||||
if err != nil {
|
if _, err := cfgToml.Save(output); err != nil {
|
||||||
return err
|
return fmt.Errorf("failed to save config: %v", err)
|
||||||
}
|
}
|
||||||
cfgToml.Save(output)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,8 +85,7 @@ func (m command) run(c *cli.Context, opts *flags.Options) error {
|
|||||||
}
|
}
|
||||||
defer output.Close()
|
defer output.Close()
|
||||||
|
|
||||||
_, err = cfgToml.Save(output)
|
if _, err = cfgToml.Save(output); err != nil {
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to write output: %v", err)
|
return fmt.Errorf("failed to write output: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,9 @@ func (i additionalInfo) UsesNVGPUModule() (uses bool, reason string) {
|
|||||||
if ret != nvml.SUCCESS {
|
if ret != nvml.SUCCESS {
|
||||||
return false, fmt.Sprintf("failed to initialize nvml: %v", ret)
|
return false, fmt.Sprintf("failed to initialize nvml: %v", ret)
|
||||||
}
|
}
|
||||||
defer i.nvmllib.Shutdown()
|
defer func() {
|
||||||
|
_ = i.nvmllib.Shutdown()
|
||||||
|
}()
|
||||||
|
|
||||||
var names []string
|
var names []string
|
||||||
|
|
||||||
|
@ -22,7 +22,8 @@ func TestMaintainSpec(t *testing.T) {
|
|||||||
|
|
||||||
spec := NewFileSpec(inputSpecPath).(*fileSpec)
|
spec := NewFileSpec(inputSpecPath).(*fileSpec)
|
||||||
|
|
||||||
spec.Load()
|
_, err := spec.Load()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
outputSpecPath := filepath.Join(moduleRoot, "test/output", f)
|
outputSpecPath := filepath.Join(moduleRoot, "test/output", f)
|
||||||
spec.path = outputSpecPath
|
spec.path = outputSpecPath
|
||||||
|
@ -18,6 +18,7 @@ package runtime
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -53,7 +54,9 @@ func (r rt) Run(argv []string) (rerr error) {
|
|||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
r.logger.Errorf("%v", rerr)
|
r.logger.Errorf("%v", rerr)
|
||||||
}
|
}
|
||||||
r.logger.Reset()
|
if err := r.logger.Reset(); err != nil {
|
||||||
|
rerr = errors.Join(rerr, fmt.Errorf("failed to reset logger: %v", err))
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// We apply some config updates here to ensure that the config is valid in
|
// We apply some config updates here to ensure that the config is valid in
|
||||||
|
@ -36,7 +36,11 @@ func NewDriverDiscoverer(logger logger.Interface, driverRoot string, nvidiaCTKPa
|
|||||||
if r := nvmllib.Init(); r != nvml.SUCCESS {
|
if r := nvmllib.Init(); r != nvml.SUCCESS {
|
||||||
return nil, fmt.Errorf("failed to initialize NVML: %v", r)
|
return nil, fmt.Errorf("failed to initialize NVML: %v", r)
|
||||||
}
|
}
|
||||||
defer nvmllib.Shutdown()
|
defer func() {
|
||||||
|
if r := nvmllib.Shutdown(); r != nvml.SUCCESS {
|
||||||
|
logger.Warningf("failed to shutdown NVML: %v", r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
version, r := nvmllib.SystemGetDriverVersion()
|
version, r := nvmllib.SystemGetDriverVersion()
|
||||||
if r != nvml.SUCCESS {
|
if r != nvml.SUCCESS {
|
||||||
|
@ -43,7 +43,11 @@ func newWSLDriverDiscoverer(logger logger.Interface, driverRoot string, nvidiaCT
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to initialize dxcore: %v", err)
|
return nil, fmt.Errorf("failed to initialize dxcore: %v", err)
|
||||||
}
|
}
|
||||||
defer dxcore.Shutdown()
|
defer func() {
|
||||||
|
if err := dxcore.Shutdown(); err != nil {
|
||||||
|
logger.Warningf("failed to shutdown dxcore: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
driverStorePaths := dxcore.GetDriverStorePaths()
|
driverStorePaths := dxcore.GetDriverStorePaths()
|
||||||
if len(driverStorePaths) == 0 {
|
if len(driverStorePaths) == 0 {
|
||||||
|
@ -43,7 +43,11 @@ func (l *nvmllib) GetAllDeviceSpecs() ([]specs.Device, error) {
|
|||||||
if r := l.nvmllib.Init(); r != nvml.SUCCESS {
|
if r := l.nvmllib.Init(); r != nvml.SUCCESS {
|
||||||
return nil, fmt.Errorf("failed to initialize NVML: %v", r)
|
return nil, fmt.Errorf("failed to initialize NVML: %v", r)
|
||||||
}
|
}
|
||||||
defer l.nvmllib.Shutdown()
|
defer func() {
|
||||||
|
if r := l.nvmllib.Shutdown(); r != nvml.SUCCESS {
|
||||||
|
l.logger.Warningf("failed to shutdown NVML: %v", r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
gpuDeviceSpecs, err := l.getGPUDeviceSpecs()
|
gpuDeviceSpecs, err := l.getGPUDeviceSpecs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -191,7 +191,11 @@ func (l *nvcdilib) getCudaVersion() (string, error) {
|
|||||||
if r != nvml.SUCCESS {
|
if r != nvml.SUCCESS {
|
||||||
return "", fmt.Errorf("failed to initialize nvml: %v", r)
|
return "", fmt.Errorf("failed to initialize nvml: %v", r)
|
||||||
}
|
}
|
||||||
defer l.nvmllib.Shutdown()
|
defer func() {
|
||||||
|
if r := l.nvmllib.Shutdown(); r != nvml.SUCCESS {
|
||||||
|
l.logger.Warningf("failed to shutdown NVML: %v", r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
version, r := l.nvmllib.SystemGetDriverVersion()
|
version, r := l.nvmllib.SystemGetDriverVersion()
|
||||||
if r != nvml.SUCCESS {
|
if r != nvml.SUCCESS {
|
||||||
|
@ -455,13 +455,14 @@ func installToolkitConfig(c *cli.Context, toolkitConfigPath string, nvidiaContai
|
|||||||
config.Set(key, value)
|
config.Set(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = config.WriteTo(targetConfig)
|
if _, err := config.WriteTo(targetConfig); err != nil {
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error writing config: %v", err)
|
return fmt.Errorf("error writing config: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Stdout.WriteString("Using config:\n")
|
os.Stdout.WriteString("Using config:\n")
|
||||||
config.WriteTo(os.Stdout)
|
if _, err = config.WriteTo(os.Stdout); err != nil {
|
||||||
|
log.Warningf("Failed to output config to STDOUT: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user