Skip to content
Snippets Groups Projects
Commit 96380d79 authored by Fabian Seidl's avatar Fabian Seidl
Browse files

enabled error linting and fixed problems with wron error checks

parent a324c537
No related branches found
No related tags found
1 merge request!363Resolve "Improve security by enabling and enforcing more linting rules"
Pipeline #110718 passed
This commit is part of merge request !363. Comments created here will be created in the context of that merge request.
...@@ -33,7 +33,7 @@ issues: ...@@ -33,7 +33,7 @@ issues:
linters: linters:
# enable the specific needed linters # enable the specific needed linters
# see here for full list: https://golangci-lint.run/usage/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 disable-all: true
enable: enable:
- gofmt - gofmt
...@@ -52,6 +52,8 @@ linters: ...@@ -52,6 +52,8 @@ linters:
- asciicheck - asciicheck
- bidichk - bidichk
- durationcheck - durationcheck
- errchkjson
- errorlint
# custom settings for linters # custom settings for linters
linters-settings: linters-settings:
......
...@@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
package cmd package cmd
import ( import (
"errors"
"io" "io"
"code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd" "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. ...@@ -79,7 +80,8 @@ The device UUID and requested paths must be specified as a positional arguments.
subscribeResponse, err := subClient.Recv() subscribeResponse, err := subClient.Recv()
if err != nil { if err != nil {
if err != nil { if err != nil {
if err == io.EOF {
if errors.Is(err, io.EOF) {
break break
} }
log.Error(err) log.Error(err)
......
...@@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE.
package cmd package cmd
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
...@@ -108,7 +109,7 @@ func initConfig() { ...@@ -108,7 +109,7 @@ func initConfig() {
// If a config file is found, read it in. // If a config file is found, read it in.
if err := viper.ReadInConfig(); err != nil { 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 // create folder if it does not exist
if err := os.MkdirAll(defaultPath, 0777); err != nil { if err := os.MkdirAll(defaultPath, 0777); err != nil {
log.Error("Config directory not found and was unable to create, error: ", err) log.Error("Config directory not found and was unable to create, error: ", err)
......
...@@ -2,6 +2,7 @@ package api ...@@ -2,6 +2,7 @@ package api
import ( import (
"context" "context"
"errors"
"testing" "testing"
"code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd" "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
...@@ -31,9 +32,7 @@ func TestApiIntegration(t *testing.T) { ...@@ -31,9 +32,7 @@ func TestApiIntegration(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
defer viper.Reset() defer viper.Reset()
if err := Init(context.TODO(), testAPIEndpoint); (err != nil) != tt.wantErr { if err := Init(context.TODO(), testAPIEndpoint); (err != nil) != tt.wantErr {
switch err.(type) { if errors.As(err, &viper.ConfigFileNotFoundError{}) {
case viper.ConfigFileNotFoundError:
default:
t.Errorf("gosdn cli init error = %v, wantErr %v", err, tt.wantErr) t.Errorf("gosdn cli init error = %v, wantErr %v", err, tt.wantErr)
return return
} }
......
...@@ -2,6 +2,7 @@ package api ...@@ -2,6 +2,7 @@ package api
import ( import (
"context" "context"
"errors"
"io" "io"
"time" "time"
...@@ -96,7 +97,7 @@ func GetSbiSchemaTree(ctx context.Context, addr string, pid, sid uuid.UUID) (map ...@@ -96,7 +97,7 @@ func GetSbiSchemaTree(ctx context.Context, addr string, pid, sid uuid.UUID) (map
for { for {
payload, err := sClient.Recv() payload, err := sClient.Recv()
if err != nil { if err != nil {
if err == io.EOF { if errors.Is(err, io.EOF) {
break break
} }
log.Error(err) log.Error(err)
......
...@@ -2,6 +2,7 @@ package server ...@@ -2,6 +2,7 @@ package server
import ( import (
"bytes" "bytes"
"errors"
"io" "io"
spb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/southbound" 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 ...@@ -68,7 +69,7 @@ func (s SbiServer) GetSchema(request *spb.GetSchemaRequest, stream spb.SbiServic
for { for {
n, err := schema.Read(buffer) n, err := schema.Read(buffer)
if err != nil { if err != nil {
if err != io.EOF { if errors.Is(err, io.EOF) {
log.Println(err) log.Println(err)
} }
break break
......
...@@ -3,6 +3,7 @@ package nucleus ...@@ -3,6 +3,7 @@ package nucleus
import ( import (
"context" "context"
"encoding/json" "encoding/json"
goErrors "errors"
"fmt" "fmt"
"io" "io"
"os" "os"
...@@ -884,7 +885,7 @@ func saveStreamToFile[T StreamClient](sc T, filename string, id uuid.UUID) error ...@@ -884,7 +885,7 @@ func saveStreamToFile[T StreamClient](sc T, filename string, id uuid.UUID) error
for { for {
payload, err := sc.Recv() payload, err := sc.Recv()
if err != nil { if err != nil {
if err == io.EOF { if goErrors.Is(err, io.EOF) {
break break
} }
closeErr := sc.CloseSend() closeErr := sc.CloseSend()
......
...@@ -2,6 +2,7 @@ package csbi ...@@ -2,6 +2,7 @@ package csbi
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
...@@ -136,7 +137,7 @@ func (s server) GetFile(req *pb.GetPayloadRequest, stream pb.CsbiService_GetFile ...@@ -136,7 +137,7 @@ func (s server) GetFile(req *pb.GetPayloadRequest, stream pb.CsbiService_GetFile
for { for {
n, err := file.Read(buffer) n, err := file.Read(buffer)
if err != nil { if err != nil {
if err != io.EOF { if errors.Is(err, io.EOF) {
fmt.Println(err) fmt.Println(err)
} }
break break
......
...@@ -28,7 +28,7 @@ import ( ...@@ -28,7 +28,7 @@ import (
// The output includes a package header which is generated. // The output includes a package header which is generated.
func write(ctx context.Context, code *ygen.GeneratedGoCode, path string, sbiType spb.Type) error { func write(ctx context.Context, code *ygen.GeneratedGoCode, path string, sbiType spb.Type) error {
if err := os.Mkdir(path, 0755); err != nil { 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 return err
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment