@@ -17,10 +17,13 @@ type fetcher struct {
17
17
}
18
18
19
19
//nolint:revive
20
- func NewFetcher (f * clistat.Statter ) * fetcher {
21
- isContainerized , _ := f .IsContainerized ()
20
+ func NewFetcher (f * clistat.Statter ) (* fetcher , error ) {
21
+ isContainerized , err := f .IsContainerized ()
22
+ if err != nil {
23
+ return nil , xerrors .Errorf ("check is containerized: %w" , err )
24
+ }
22
25
23
- return & fetcher {f , isContainerized }
26
+ return & fetcher {f , isContainerized }, nil
24
27
}
25
28
26
29
func (f * fetcher ) FetchMemory () (total int64 , used int64 , err error ) {
@@ -29,7 +32,7 @@ func (f *fetcher) FetchMemory() (total int64, used int64, err error) {
29
32
if f .isContainerized {
30
33
mem , err = f .ContainerMemory (clistat .PrefixDefault )
31
34
if err != nil {
32
- return 0 , 0 , xerrors .Errorf ("failed to fetch container memory: %w" , err )
35
+ return 0 , 0 , xerrors .Errorf ("fetch container memory: %w" , err )
33
36
}
34
37
35
38
// A container might not have a memory limit set. If this
@@ -38,15 +41,15 @@ func (f *fetcher) FetchMemory() (total int64, used int64, err error) {
38
41
if mem .Total == nil {
39
42
hostMem , err := f .HostMemory (clistat .PrefixDefault )
40
43
if err != nil {
41
- return 0 , 0 , xerrors .Errorf ("failed to host fetch memory: %w" , err )
44
+ return 0 , 0 , xerrors .Errorf ("fetch host memory: %w" , err )
42
45
}
43
46
44
47
mem .Total = hostMem .Total
45
48
}
46
49
} else {
47
50
mem , err = f .HostMemory (clistat .PrefixDefault )
48
51
if err != nil {
49
- return 0 , 0 , xerrors .Errorf ("failed to host fetch memory: %w" , err )
52
+ return 0 , 0 , xerrors .Errorf ("fetch host memory: %w" , err )
50
53
}
51
54
}
52
55
0 commit comments