From 58a6c0a2dc366080d4970672e6073b4da26512bd Mon Sep 17 00:00:00 2001
From: SuperQ <superq@gmail.com>
Date: Thu, 22 Dec 2022 12:25:50 +0100
Subject: [PATCH] Use errors.Is() for invalid argument

Switch to using Go errors.Is() to check for the "invalid argument"
error.

Signed-off-by: SuperQ <superq@gmail.com>
---
 sysfs/class_fibrechannel.go | 3 ++-
 sysfs/class_infiniband.go   | 5 +++--
 sysfs/class_power_supply.go | 3 ++-
 sysfs/net_class.go          | 3 ++-
 4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/sysfs/class_fibrechannel.go b/sysfs/class_fibrechannel.go
index 28a871dd0..d7e62784b 100644
--- a/sysfs/class_fibrechannel.go
+++ b/sysfs/class_fibrechannel.go
@@ -17,6 +17,7 @@
 package sysfs
 
 import (
+	"errors"
 	"fmt"
 	"os"
 	"path/filepath"
@@ -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)
diff --git a/sysfs/class_infiniband.go b/sysfs/class_infiniband.go
index 679cb9686..652b544b5 100644
--- a/sysfs/class_infiniband.go
+++ b/sysfs/class_infiniband.go
@@ -17,6 +17,7 @@
 package sysfs
 
 import (
+	"errors"
 	"fmt"
 	"os"
 	"path/filepath"
@@ -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)
@@ -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)
diff --git a/sysfs/class_power_supply.go b/sysfs/class_power_supply.go
index 9969f0114..c50c32b37 100644
--- a/sysfs/class_power_supply.go
+++ b/sysfs/class_power_supply.go
@@ -17,6 +17,7 @@
 package sysfs
 
 import (
+	"errors"
 	"fmt"
 	"os"
 	"path/filepath"
@@ -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)
diff --git a/sysfs/net_class.go b/sysfs/net_class.go
index 364906ecb..0c8cb2845 100644
--- a/sysfs/net_class.go
+++ b/sysfs/net_class.go
@@ -17,6 +17,7 @@
 package sysfs
 
 import (
+	"errors"
 	"fmt"
 	"os"
 	"path/filepath"
@@ -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)