Skip to content

Commit bb7727a

Browse files
authored
Merge pull request #483 from prometheus/superq/err_invalid
Use errors.Is() for invalid argument
2 parents 0c4b3aa + 58a6c0a commit bb7727a

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

sysfs/class_fibrechannel.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package sysfs
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"os"
2223
"path/filepath"
@@ -161,7 +162,7 @@ func parseFibreChannelStatistics(hostPath string) (*FibreChannelCounters, error)
161162
value, err := util.SysReadFile(name)
162163
if err != nil {
163164
// there are some write-only files in this directory; we can safely skip over them
164-
if os.IsNotExist(err) || err.Error() == "operation not supported" || err.Error() == "invalid argument" {
165+
if os.IsNotExist(err) || err.Error() == "operation not supported" || errors.Is(err, os.ErrInvalid) {
165166
continue
166167
}
167168
return nil, fmt.Errorf("failed to read file %q: %w", name, err)

sysfs/class_infiniband.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package sysfs
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"os"
2223
"path/filepath"
@@ -261,7 +262,7 @@ func parseInfiniBandCounters(portPath string) (*InfiniBandCounters, error) {
261262
name := filepath.Join(path, f.Name())
262263
value, err := util.SysReadFile(name)
263264
if err != nil {
264-
if os.IsNotExist(err) || os.IsPermission(err) || err.Error() == "operation not supported" || err.Error() == "invalid argument" {
265+
if os.IsNotExist(err) || os.IsPermission(err) || err.Error() == "operation not supported" || errors.Is(err, os.ErrInvalid) {
265266
continue
266267
}
267268
return nil, fmt.Errorf("failed to read file %q: %w", name, err)
@@ -356,7 +357,7 @@ func parseInfiniBandCounters(portPath string) (*InfiniBandCounters, error) {
356357
name := filepath.Join(path, f.Name())
357358
value, err := util.SysReadFile(name)
358359
if err != nil {
359-
if os.IsNotExist(err) || os.IsPermission(err) || err.Error() == "operation not supported" || err.Error() == "invalid argument" {
360+
if os.IsNotExist(err) || os.IsPermission(err) || err.Error() == "operation not supported" || errors.Is(err, os.ErrInvalid) {
360361
continue
361362
}
362363
return nil, fmt.Errorf("failed to read file %q: %w", name, err)

sysfs/class_power_supply.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package sysfs
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"os"
2223
"path/filepath"
@@ -142,7 +143,7 @@ func parsePowerSupply(path string) (*PowerSupply, error) {
142143
name := filepath.Join(path, f.Name())
143144
value, err := util.SysReadFile(name)
144145
if err != nil {
145-
if os.IsNotExist(err) || err.Error() == "operation not supported" || err.Error() == "invalid argument" {
146+
if os.IsNotExist(err) || err.Error() == "operation not supported" || errors.Is(err, os.ErrInvalid) {
146147
continue
147148
}
148149
return nil, fmt.Errorf("failed to read file %q: %w", name, err)

sysfs/net_class.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package sysfs
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"os"
2223
"path/filepath"
@@ -133,7 +134,7 @@ func parseNetClassIface(devicePath string) (*NetClassIface, error) {
133134
name := filepath.Join(devicePath, f.Name())
134135
value, err := util.SysReadFile(name)
135136
if err != nil {
136-
if os.IsNotExist(err) || os.IsPermission(err) || err.Error() == "operation not supported" || err.Error() == "invalid argument" {
137+
if os.IsNotExist(err) || os.IsPermission(err) || err.Error() == "operation not supported" || errors.Is(err, os.ErrInvalid) {
137138
continue
138139
}
139140
return nil, fmt.Errorf("failed to read file %q: %w", name, err)

0 commit comments

Comments
 (0)