diff --git a/.golangci.yml b/.golangci.yml index df0060e12645c0936cb4e827b4cb9c7dd61a1ae7..66c0d518289d53f33159b62bc541b8a552b131d0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -33,7 +33,7 @@ issues: linters: # enable the specific needed linters # see here for full list: https://golangci-lint.run/usage/linters/ - # linters to consider: gosimple, containedctx, contextcheck, depguard + # linters to consider: gosimple, containedctx, contextcheck, depguard, errname disable-all: true enable: - gofmt @@ -52,6 +52,8 @@ linters: - asciicheck - bidichk - durationcheck + - errchkjson + - errorlint # custom settings for linters linters-settings: diff --git a/cli/cmd/deviceSubscribe.go b/cli/cmd/deviceSubscribe.go index e3718790bf9d233ca9389048ae629148b785d4ac..691fed1593d60f774b850194a0ebcec252b5499f 100644 --- a/cli/cmd/deviceSubscribe.go +++ b/cli/cmd/deviceSubscribe.go @@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. package cmd import ( + "errors" "io" "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd" @@ -79,7 +80,8 @@ The device UUID and requested paths must be specified as a positional arguments. subscribeResponse, err := subClient.Recv() if err != nil { if err != nil { - if err == io.EOF { + + if errors.Is(err, io.EOF) { break } log.Error(err) diff --git a/cli/cmd/root.go b/cli/cmd/root.go index f64c570325085908932d9457966d004d1685a541..40ad5467dd117c8ba312ab403f8f5a17821528b6 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE. package cmd import ( + "errors" "fmt" "os" @@ -108,7 +109,7 @@ func initConfig() { // If a config file is found, read it in. if err := viper.ReadInConfig(); err != nil { - if _, ok := err.(viper.ConfigFileNotFoundError); ok { + if ok := errors.As(err, &viper.ConfigFileNotFoundError{}); ok { // create folder if it does not exist if err := os.MkdirAll(defaultPath, 0777); err != nil { log.Error("Config directory not found and was unable to create, error: ", err) diff --git a/controller/api/apiIntegration_test.go b/controller/api/apiIntegration_test.go index a97a54820db061d3e85f91105982bb903c2547cb..39829243fb344712ce5f020a007939d77bea196a 100644 --- a/controller/api/apiIntegration_test.go +++ b/controller/api/apiIntegration_test.go @@ -2,6 +2,7 @@ package api import ( "context" + "errors" "testing" "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd" @@ -31,9 +32,7 @@ func TestApiIntegration(t *testing.T) { t.Run(tt.name, func(t *testing.T) { defer viper.Reset() if err := Init(context.TODO(), testAPIEndpoint); (err != nil) != tt.wantErr { - switch err.(type) { - case viper.ConfigFileNotFoundError: - default: + if errors.As(err, &viper.ConfigFileNotFoundError{}) { t.Errorf("gosdn cli init error = %v, wantErr %v", err, tt.wantErr) return } diff --git a/controller/api/device.go b/controller/api/device.go index 35f211724d87cef0111344c9bc116196643b869e..91cb3aa67613e2d240d6f125f7c6ab3ddce15f83 100644 --- a/controller/api/device.go +++ b/controller/api/device.go @@ -2,6 +2,7 @@ package api import ( "context" + "errors" "io" "time" @@ -96,7 +97,7 @@ func GetSbiSchemaTree(ctx context.Context, addr string, pid, sid uuid.UUID) (map for { payload, err := sClient.Recv() if err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { break } log.Error(err) diff --git a/controller/northbound/server/sbi.go b/controller/northbound/server/sbi.go index a8358dd23f6521bffc7ff7afcaed810363afdd37..aefdc38baf3e215d7fe9d41c2839041594755e31 100644 --- a/controller/northbound/server/sbi.go +++ b/controller/northbound/server/sbi.go @@ -2,6 +2,7 @@ package server import ( "bytes" + "errors" "io" spb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/southbound" @@ -68,7 +69,7 @@ func (s SbiServer) GetSchema(request *spb.GetSchemaRequest, stream spb.SbiServic for { n, err := schema.Read(buffer) if err != nil { - if err != io.EOF { + if errors.Is(err, io.EOF) { log.Println(err) } break diff --git a/controller/nucleus/principalNetworkDomain.go b/controller/nucleus/principalNetworkDomain.go index 566d6623b37017bf8f63f2c903c6ec715a09279c..fc369e836c8b2bb58713615b39722c25d87f8169 100644 --- a/controller/nucleus/principalNetworkDomain.go +++ b/controller/nucleus/principalNetworkDomain.go @@ -3,6 +3,7 @@ package nucleus import ( "context" "encoding/json" + goErrors "errors" "fmt" "io" "os" @@ -884,7 +885,7 @@ func saveStreamToFile[T StreamClient](sc T, filename string, id uuid.UUID) error for { payload, err := sc.Recv() if err != nil { - if err == io.EOF { + if goErrors.Is(err, io.EOF) { break } closeErr := sc.CloseSend() diff --git a/csbi/grpc.go b/csbi/grpc.go index 438cc5ca85218574fe4433d3bcabcfad0a61b2b0..80b772cfd658adcec76ad54795d17b5760cf6a4f 100644 --- a/csbi/grpc.go +++ b/csbi/grpc.go @@ -2,6 +2,7 @@ package csbi import ( "context" + "errors" "fmt" "io" "os" @@ -136,7 +137,7 @@ func (s server) GetFile(req *pb.GetPayloadRequest, stream pb.CsbiService_GetFile for { n, err := file.Read(buffer) if err != nil { - if err != io.EOF { + if errors.Is(err, io.EOF) { fmt.Println(err) } break diff --git a/csbi/write.go b/csbi/write.go index ed6396c36c22e515fb0293e3cb6620971f9d741d..78dab546d5799cc2d15673d6296edaf6050c3770 100644 --- a/csbi/write.go +++ b/csbi/write.go @@ -28,7 +28,7 @@ import ( // The output includes a package header which is generated. func write(ctx context.Context, code *ygen.GeneratedGoCode, path string, sbiType spb.Type) error { if err := os.Mkdir(path, 0755); err != nil { - if err.(*fs.PathError).Err.Error() != "file exists" { + if err.(*fs.PathError).Err.Error() != "file exists" { //nolint:errorlint return err } }