From 98544a3585cf9230fcdbc1afa0b4bd7895f332d1 Mon Sep 17 00:00:00 2001 From: Jian Wang Date: Thu, 22 Feb 2024 17:26:35 +0100 Subject: [PATCH] Add file name to device type check failure message Signed-off-by: Jian Wang --- pkg/oci/utils_unix.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/oci/utils_unix.go b/pkg/oci/utils_unix.go index 7606ec8e3..9e01ab079 100644 --- a/pkg/oci/utils_unix.go +++ b/pkg/oci/utils_unix.go @@ -30,6 +30,7 @@ import ( ) // ErrNotADevice denotes that a file is not a valid linux device. +// When checking this error, use errors.Is(err, oci.ErrNotADevice) var ErrNotADevice = errors.New("not a device node") // Testing dependencies @@ -53,6 +54,10 @@ func getDevices(path, containerPath string) ([]specs.LinuxDevice, error) { if !stat.IsDir() { dev, err := DeviceFromPath(path) if err != nil { + // wrap error with detailed path and container path when it is ErrNotADevice + if err == ErrNotADevice { + return nil, fmt.Errorf("get device path: %q containerPath: %q error: %w", path, containerPath, err) + } return nil, err } if containerPath != "" {