From 1baab56dd679e75944677ffc2cb87fe514d65b56 Mon Sep 17 00:00:00 2001 From: Dmitry Voropaev Date: Mon, 28 Sep 2026 22:16:46 +0300 Subject: [PATCH] Report why the host CUDA version could not be read getEnableCUDACompatHookOptions formats the error from getCUDAVersionString with ret, the NVML return of the Init call forty lines up, instead of err. Init is checked and returns early on anything but SUCCESS, so ret is always SUCCESS by then and the message reads failed to get host CUDA version: SUCCESS while the only description of the failure, err, is dropped. The wrapped value is an nvml.Return, so it is also what a caller would match on. Wrap err with %w, as the rest of the file does. Signed-off-by: Dmitry Voropaev --- pkg/nvcdi/lib-csv.go | 2 +- pkg/nvcdi/lib-csv_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/pkg/nvcdi/lib-csv.go b/pkg/nvcdi/lib-csv.go index 603fd46bf..90c18b554 100644 --- a/pkg/nvcdi/lib-csv.go +++ b/pkg/nvcdi/lib-csv.go @@ -476,7 +476,7 @@ func (l *csvlib) getEnableCUDACompatHookOptions() (*discover.EnableCUDACompatHoo hostCUDAVersion, err := l.getCUDAVersionString() if err != nil { - return nil, fmt.Errorf("failed to get host CUDA version: %v", ret) + return nil, fmt.Errorf("failed to get host CUDA version: %w", err) } f := &discover.EnableCUDACompatHookOptions{ diff --git a/pkg/nvcdi/lib-csv_test.go b/pkg/nvcdi/lib-csv_test.go index 07a342d92..ff71b407b 100644 --- a/pkg/nvcdi/lib-csv_test.go +++ b/pkg/nvcdi/lib-csv_test.go @@ -405,3 +405,30 @@ func mockIGXServer() nvml.Interface { }, } } + +func TestGetEnableCUDACompatHookOptionsReportsWhyTheVersionFailed(t *testing.T) { + // The message used to interpolate the NVML return of the Init call above it, + // which is always SUCCESS by then, so the real failure was dropped. + nvmllib := &mock.Interface{ + InitFunc: func() nvml.Return { return nvml.SUCCESS }, + ShutdownFunc: func() nvml.Return { return nvml.SUCCESS }, + SystemGetCudaDriverVersionFunc: func() (int, nvml.Return) { + return 0, nvml.ERROR_NOT_SUPPORTED + }, + DeviceGetCountFunc: func() (int, nvml.Return) { return 0, nvml.SUCCESS }, + } + + l := &csvlib{ + platformlibs: platformlibs{ + infolib: &infoInterfaceMock{ + HasNvmlFunc: func() (bool, string) { return true, "forced" }, + }, + nvmllib: nvmllib, + devicelib: device.New(nvmllib), + }, + } + + _, err := l.getEnableCUDACompatHookOptions() + require.ErrorContains(t, err, nvml.ERROR_NOT_SUPPORTED.Error()) + require.NotContains(t, err.Error(), nvml.SUCCESS.Error()) +}