Skip to content

Commit

Permalink
Use errors.Is() for invalid argument
Browse files Browse the repository at this point in the history
Switch to using Go errors.Is() to check for the "invalid argument"
error.

Signed-off-by: SuperQ <[email protected]>
  • Loading branch information
SuperQ committed Dec 22, 2022
1 parent 85417ca commit 58a6c0a
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 58a6c0a

Please sign in to comment.