Skip to content

Commit 8f4d3e3

Browse files
committed
Add custom error type if device not found in partitions map
The new error type `ErrDeviceNotInPartisionsMap` can be used by external consumers like Kubernetes to distinguish certain error paths. Refers to kubernetes/kubernetes#100448 Signed-off-by: Sascha Grunert <[email protected]>
1 parent 7990be2 commit 8f4d3e3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

fs/fs.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package fs
1919

2020
import (
2121
"bufio"
22+
"errors"
2223
"fmt"
2324
"io/ioutil"
2425
"os"
@@ -56,6 +57,9 @@ const (
5657
// A pool for restricting the number of consecutive `du` and `find` tasks running.
5758
var pool = make(chan struct{}, maxConcurrentOps)
5859

60+
// ErrDeviceNotInPartitionsMap is the error resulting if a device could not be found in the partitions map.
61+
var ErrDeviceNotInPartitionsMap = errors.New("could not find device in cached partitions map")
62+
5963
func init() {
6064
for i := 0; i < maxConcurrentOps; i++ {
6165
releaseToken()
@@ -595,7 +599,7 @@ func (i *RealFsInfo) GetDirFsDevice(dir string) (*DeviceInfo, error) {
595599
return &DeviceInfo{mnt.Source, uint(major), uint(minor)}, nil
596600
}
597601

598-
return nil, fmt.Errorf("could not find device with major: %d, minor: %d in cached partitions map", major, minor)
602+
return nil, fmt.Errorf("with major: %d, minor: %d: %w", major, minor, ErrDeviceNotInPartitionsMap)
599603
}
600604

601605
func GetDirUsage(dir string) (UsageInfo, error) {

0 commit comments

Comments
 (0)