Add file name to device type check failure message

Signed-off-by: Jian Wang <w13915984028@gmail.com>
This commit is contained in:
Jian Wang 2024-02-22 17:26:35 +01:00
parent 3b0b3e533c
commit 98544a3585

View File

@ -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 != "" {