Skip to content

Commit

Permalink
Merge pull request #483 from prometheus/superq/err_invalid
Browse files Browse the repository at this point in the history
Use errors.Is() for invalid argument
  • Loading branch information
SuperQ committed Dec 22, 2022
2 parents 0c4b3aa + 58a6c0a commit bb7727a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion sysfs/class_fibrechannel.go
Expand Up @@ -17,6 +17,7 @@
package sysfs

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -161,7 +162,7 @@ func parseFibreChannelStatistics(hostPath string) (*FibreChannelCounters, error)
value, err := util.SysReadFile(name)
if err != nil {
// there are some write-only files in this directory; we can safely skip over them
if os.IsNotExist(err) || err.Error() == "operation not supported" || err.Error() == "invalid argument" {
if os.IsNotExist(err) || err.Error() == "operation not supported" || errors.Is(err, os.ErrInvalid) {
continue
}
return nil, fmt.Errorf("failed to read file %q: %w", name, err)
Expand Down
5 changes: 3 additions & 2 deletions sysfs/class_infiniband.go
Expand Up @@ -17,6 +17,7 @@
package sysfs

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -261,7 +262,7 @@ func parseInfiniBandCounters(portPath string) (*InfiniBandCounters, error) {
name := filepath.Join(path, f.Name())
value, err := util.SysReadFile(name)
if err != nil {
if os.IsNotExist(err) || os.IsPermission(err) || err.Error() == "operation not supported" || err.Error() == "invalid argument" {
if os.IsNotExist(err) || os.IsPermission(err) || err.Error() == "operation not supported" || errors.Is(err, os.ErrInvalid) {
continue
}
return nil, fmt.Errorf("failed to read file %q: %w", name, err)
Expand Down Expand Up @@ -356,7 +357,7 @@ func parseInfiniBandCounters(portPath string) (*InfiniBandCounters, error) {
name := filepath.Join(path, f.Name())
value, err := util.SysReadFile(name)
if err != nil {
if os.IsNotExist(err) || os.IsPermission(err) || err.Error() == "operation not supported" || err.Error() == "invalid argument" {
if os.IsNotExist(err) || os.IsPermission(err) || err.Error() == "operation not supported" || errors.Is(err, os.ErrInvalid) {
continue
}
return nil, fmt.Errorf("failed to read file %q: %w", name, err)
Expand Down
3 changes: 2 additions & 1 deletion sysfs/class_power_supply.go
Expand Up @@ -17,6 +17,7 @@
package sysfs

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -142,7 +143,7 @@ func parsePowerSupply(path string) (*PowerSupply, error) {
name := filepath.Join(path, f.Name())
value, err := util.SysReadFile(name)
if err != nil {
if os.IsNotExist(err) || err.Error() == "operation not supported" || err.Error() == "invalid argument" {
if os.IsNotExist(err) || err.Error() == "operation not supported" || errors.Is(err, os.ErrInvalid) {
continue
}
return nil, fmt.Errorf("failed to read file %q: %w", name, err)
Expand Down
3 changes: 2 additions & 1 deletion sysfs/net_class.go
Expand Up @@ -17,6 +17,7 @@
package sysfs

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -133,7 +134,7 @@ func parseNetClassIface(devicePath string) (*NetClassIface, error) {
name := filepath.Join(devicePath, f.Name())
value, err := util.SysReadFile(name)
if err != nil {
if os.IsNotExist(err) || os.IsPermission(err) || err.Error() == "operation not supported" || err.Error() == "invalid argument" {
if os.IsNotExist(err) || os.IsPermission(err) || err.Error() == "operation not supported" || errors.Is(err, os.ErrInvalid) {
continue
}
return nil, fmt.Errorf("failed to read file %q: %w", name, err)
Expand Down

0 comments on commit bb7727a

Please sign in to comment.