瀏覽代碼

lint: error handling cleanup (#1877)

mmetc 2 年之前
父節點
當前提交
104f5d1fe6
共有 43 個文件被更改,包括 102 次插入110 次删除
  1. 0 10
      .github/workflows/ci_golangci-lint.yml
  2. 1 0
      .golangci.yml
  3. 1 1
      cmd/crowdsec-cli/alerts.go
  4. 1 1
      cmd/crowdsec-cli/alerts_table.go
  5. 1 1
      cmd/crowdsec-cli/bouncers.go
  6. 5 5
      cmd/crowdsec-cli/dashboard.go
  7. 2 2
      cmd/crowdsec-cli/decisions.go
  8. 1 1
      cmd/crowdsec-cli/hubtest.go
  9. 1 1
      cmd/crowdsec-cli/machines.go
  10. 2 2
      cmd/crowdsec-cli/main.go
  11. 1 1
      cmd/crowdsec-cli/metrics.go
  12. 1 1
      cmd/crowdsec-cli/notifications.go
  13. 1 1
      cmd/crowdsec-cli/simulation.go
  14. 3 3
      cmd/crowdsec-cli/support.go
  15. 1 1
      cmd/crowdsec/api.go
  16. 1 1
      cmd/crowdsec/run_in_svc.go
  17. 1 1
      cmd/crowdsec/win_service.go
  18. 4 4
      pkg/acquisition/acquisition.go
  19. 4 4
      pkg/acquisition/modules/kafka/kafka_test.go
  20. 5 7
      pkg/apiclient/client_http.go
  21. 1 1
      pkg/apiclient/decisions_service_test.go
  22. 3 3
      pkg/apiserver/alerts_test.go
  23. 4 4
      pkg/apiserver/apiserver.go
  24. 2 2
      pkg/apiserver/apiserver_test.go
  25. 2 2
      pkg/apiserver/jwt_test.go
  26. 1 1
      pkg/apiserver/machines_test.go
  27. 3 3
      pkg/csconfig/api_test.go
  28. 2 2
      pkg/csconfig/common_test.go
  29. 4 4
      pkg/csconfig/cscli_test.go
  30. 1 1
      pkg/csconfig/profiles.go
  31. 1 1
      pkg/csplugin/broker.go
  32. 3 3
      pkg/cwhub/download.go
  33. 11 11
      pkg/exprhelpers/exprlib_test.go
  34. 4 3
      pkg/exprhelpers/jsonextract.go
  35. 8 8
      pkg/exprhelpers/jsonextract_test.go
  36. 2 2
      pkg/exprhelpers/xml_test.go
  37. 2 1
      pkg/leakybucket/buckets_test.go
  38. 2 1
      pkg/leakybucket/manager_load.go
  39. 2 2
      pkg/metabase/container.go
  40. 1 1
      pkg/metabase/metabase.go
  41. 1 1
      pkg/parser/node.go
  42. 2 1
      pkg/parser/parsing_test.go
  43. 3 4
      pkg/parser/stage.go

+ 0 - 10
.github/workflows/ci_golangci-lint.yml

@@ -33,16 +33,6 @@ jobs:
       - name: golangci-lint
       - name: golangci-lint
         uses: golangci/golangci-lint-action@v3
         uses: golangci/golangci-lint-action@v3
         with:
         with:
-          # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
           version: v1.50
           version: v1.50
-          # Optional: golangci-lint command line arguments.
           args: --issues-exit-code=1 --timeout 10m
           args: --issues-exit-code=1 --timeout 10m
-          # Optional: show only new issues if it's a pull request. The default value is `false`.
           only-new-issues: false
           only-new-issues: false
-          # Optional: if set to true then the all caching functionality will be complete disabled,
-          #           takes precedence over all other caching options.
-          skip-cache: false
-          # Optional: if set to true then the action don't cache or restore ~/go/pkg.
-          skip-pkg-cache: false
-          # Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
-          skip-build-cache: false

+ 1 - 0
.golangci.yml

@@ -5,6 +5,7 @@ run:
     - pkg/time/rate
     - pkg/time/rate
   skip-files:
   skip-files:
     - pkg/database/ent/generate.go
     - pkg/database/ent/generate.go
+    - pkg/yamlpatch/merge.go
     - pkg/yamlpatch/merge_test.go
     - pkg/yamlpatch/merge_test.go
 
 
 linters-settings:
 linters-settings:

+ 1 - 1
cmd/crowdsec-cli/alerts.go

@@ -420,7 +420,7 @@ cscli alerts delete -s crowdsecurity/ssh-bf"`,
 				log.Fatal("Local API is disabled, please run this command on the local API machine")
 				log.Fatal("Local API is disabled, please run this command on the local API machine")
 			}
 			}
 			if err := csConfig.LoadDBConfig(); err != nil {
 			if err := csConfig.LoadDBConfig(); err != nil {
-				log.Fatalf(err.Error())
+				log.Fatal(err)
 			}
 			}
 			dbClient, err = database.NewClient(csConfig.DbConfig)
 			dbClient, err = database.NewClient(csConfig.DbConfig)
 			if err != nil {
 			if err != nil {

+ 1 - 1
cmd/crowdsec-cli/alerts_table.go

@@ -55,7 +55,7 @@ func alertDecisionsTable(out io.Writer, alert *models.Alert) {
 	for _, decision := range alert.Decisions {
 	for _, decision := range alert.Decisions {
 		parsedDuration, err := time.ParseDuration(*decision.Duration)
 		parsedDuration, err := time.ParseDuration(*decision.Duration)
 		if err != nil {
 		if err != nil {
-			log.Errorf(err.Error())
+			log.Error(err)
 		}
 		}
 		expire := time.Now().UTC().Add(parsedDuration)
 		expire := time.Now().UTC().Add(parsedDuration)
 		if time.Now().UTC().After(expire) {
 		if time.Now().UTC().After(expire) {

+ 1 - 1
cmd/crowdsec-cli/bouncers.go

@@ -75,7 +75,7 @@ Note: This command requires database direct access, so is intended to be run on
 				log.Fatal("Local API is disabled, please run this command on the local API machine")
 				log.Fatal("Local API is disabled, please run this command on the local API machine")
 			}
 			}
 			if err := csConfig.LoadDBConfig(); err != nil {
 			if err := csConfig.LoadDBConfig(); err != nil {
-				log.Fatalf(err.Error())
+				log.Fatal(err)
 			}
 			}
 			dbClient, err = database.NewClient(csConfig.DbConfig)
 			dbClient, err = database.NewClient(csConfig.DbConfig)
 			if err != nil {
 			if err != nil {

+ 5 - 5
cmd/crowdsec-cli/dashboard.go

@@ -66,11 +66,11 @@ cscli dashboard remove
 			metabaseConfigFolderPath := filepath.Join(csConfig.ConfigPaths.ConfigDir, metabaseConfigFolder)
 			metabaseConfigFolderPath := filepath.Join(csConfig.ConfigPaths.ConfigDir, metabaseConfigFolder)
 			metabaseConfigPath = filepath.Join(metabaseConfigFolderPath, metabaseConfigFile)
 			metabaseConfigPath = filepath.Join(metabaseConfigFolderPath, metabaseConfigFile)
 			if err := os.MkdirAll(metabaseConfigFolderPath, os.ModePerm); err != nil {
 			if err := os.MkdirAll(metabaseConfigFolderPath, os.ModePerm); err != nil {
-				log.Fatalf(err.Error())
+				log.Fatal(err)
 			}
 			}
 			if err := csConfig.LoadDBConfig(); err != nil {
 			if err := csConfig.LoadDBConfig(); err != nil {
 				log.Errorf("This command requires direct database access (must be run on the local API machine)")
 				log.Errorf("This command requires direct database access (must be run on the local API machine)")
-				log.Fatalf(err.Error())
+				log.Fatal(err)
 			}
 			}
 
 
 			/*
 			/*
@@ -170,11 +170,11 @@ cscli dashboard setup -l 0.0.0.0 -p 443 --password <password>
 
 
 			mb, err := metabase.SetupMetabase(csConfig.API.Server.DbConfig, metabaseListenAddress, metabaseListenPort, metabaseUser, metabasePassword, metabaseDbPath, dockerGroup.Gid, metabaseContainerID)
 			mb, err := metabase.SetupMetabase(csConfig.API.Server.DbConfig, metabaseListenAddress, metabaseListenPort, metabaseUser, metabasePassword, metabaseDbPath, dockerGroup.Gid, metabaseContainerID)
 			if err != nil {
 			if err != nil {
-				log.Fatalf(err.Error())
+				log.Fatal(err)
 			}
 			}
 
 
 			if err := mb.DumpConfig(metabaseConfigPath); err != nil {
 			if err := mb.DumpConfig(metabaseConfigPath); err != nil {
-				log.Fatalf(err.Error())
+				log.Fatal(err)
 			}
 			}
 
 
 			log.Infof("Metabase is ready")
 			log.Infof("Metabase is ready")
@@ -203,7 +203,7 @@ cscli dashboard setup -l 0.0.0.0 -p 443 --password <password>
 		Run: func(cmd *cobra.Command, args []string) {
 		Run: func(cmd *cobra.Command, args []string) {
 			mb, err := metabase.NewMetabase(metabaseConfigPath, metabaseContainerID)
 			mb, err := metabase.NewMetabase(metabaseConfigPath, metabaseContainerID)
 			if err != nil {
 			if err != nil {
-				log.Fatalf(err.Error())
+				log.Fatal(err)
 			}
 			}
 			if err := mb.Container.Start(); err != nil {
 			if err := mb.Container.Start(); err != nil {
 				log.Fatalf("Failed to start metabase container : %s", err)
 				log.Fatalf("Failed to start metabase container : %s", err)

+ 2 - 2
cmd/crowdsec-cli/decisions.go

@@ -351,7 +351,7 @@ cscli decisions add --scope username --value foobar
 
 
 			_, _, err = Client.Alerts.Add(context.Background(), alerts)
 			_, _, err = Client.Alerts.Add(context.Background(), alerts)
 			if err != nil {
 			if err != nil {
-				log.Fatalf(err.Error())
+				log.Fatal(err)
 			}
 			}
 
 
 			log.Info("Decision successfully added")
 			log.Info("Decision successfully added")
@@ -597,7 +597,7 @@ decisions.json :
 
 
 			_, _, err = Client.Alerts.Add(context.Background(), alerts)
 			_, _, err = Client.Alerts.Add(context.Background(), alerts)
 			if err != nil {
 			if err != nil {
-				log.Fatalf(err.Error())
+				log.Fatal(err)
 			}
 			}
 			log.Infof("%d decisions successfully imported", len(decisionsList))
 			log.Infof("%d decisions successfully imported", len(decisionsList))
 		},
 		},

+ 1 - 1
cmd/crowdsec-cli/hubtest.go

@@ -483,7 +483,7 @@ cscli hubtest create my-scenario-test --parsers crowdsecurity/nginx --scenarios
 				}
 				}
 				output, err := test.ParserAssert.EvalExpression(evalExpression)
 				output, err := test.ParserAssert.EvalExpression(evalExpression)
 				if err != nil {
 				if err != nil {
-					log.Fatalf(err.Error())
+					log.Fatal(err)
 				}
 				}
 				fmt.Print(output)
 				fmt.Print(output)
 			}
 			}

+ 1 - 1
cmd/crowdsec-cli/machines.go

@@ -169,7 +169,7 @@ Note: This command requires database direct access, so is intended to be run on
 			}
 			}
 			if err := csConfig.LoadDBConfig(); err != nil {
 			if err := csConfig.LoadDBConfig(); err != nil {
 				log.Errorf("This command requires direct database access (must be run on the local API machine)")
 				log.Errorf("This command requires direct database access (must be run on the local API machine)")
-				log.Fatalf(err.Error())
+				log.Fatal(err)
 			}
 			}
 		},
 		},
 	}
 	}

+ 2 - 2
cmd/crowdsec-cli/main.go

@@ -58,11 +58,11 @@ func initConfig() {
 	if !inSlice(os.Args[1], NoNeedConfig) {
 	if !inSlice(os.Args[1], NoNeedConfig) {
 		csConfig, err = csconfig.NewConfig(ConfigFilePath, false, false)
 		csConfig, err = csconfig.NewConfig(ConfigFilePath, false, false)
 		if err != nil {
 		if err != nil {
-			log.Fatalf(err.Error())
+			log.Fatal(err)
 		}
 		}
 		log.Debugf("Using %s as configuration file", ConfigFilePath)
 		log.Debugf("Using %s as configuration file", ConfigFilePath)
 		if err := csConfig.LoadCSCLI(); err != nil {
 		if err := csConfig.LoadCSCLI(); err != nil {
-			log.Fatalf(err.Error())
+			log.Fatal(err)
 		}
 		}
 	} else {
 	} else {
 		csConfig = csconfig.NewDefaultConfig()
 		csConfig = csconfig.NewDefaultConfig()

+ 1 - 1
cmd/crowdsec-cli/metrics.go

@@ -260,7 +260,7 @@ func NewMetricsCmd() *cobra.Command {
 		DisableAutoGenTag: true,
 		DisableAutoGenTag: true,
 		Run: func(cmd *cobra.Command, args []string) {
 		Run: func(cmd *cobra.Command, args []string) {
 			if err := csConfig.LoadPrometheus(); err != nil {
 			if err := csConfig.LoadPrometheus(); err != nil {
-				log.Fatalf(err.Error())
+				log.Fatal(err)
 			}
 			}
 			if !csConfig.Prometheus.Enabled {
 			if !csConfig.Prometheus.Enabled {
 				log.Warning("Prometheus is not enabled, can't show metrics")
 				log.Warning("Prometheus is not enabled, can't show metrics")

+ 1 - 1
cmd/crowdsec-cli/notifications.go

@@ -46,7 +46,7 @@ func NewNotificationsCmd() *cobra.Command {
 				err error
 				err error
 			)
 			)
 			if err = csConfig.API.Server.LoadProfiles(); err != nil {
 			if err = csConfig.API.Server.LoadProfiles(); err != nil {
-				log.Fatalf(err.Error())
+				log.Fatal(err)
 			}
 			}
 			if csConfig.ConfigPaths.NotificationDir == "" {
 			if csConfig.ConfigPaths.NotificationDir == "" {
 				log.Fatalf("config_paths.notification_dir is not set in crowdsec config")
 				log.Fatalf("config_paths.notification_dir is not set in crowdsec config")

+ 1 - 1
cmd/crowdsec-cli/simulation.go

@@ -108,7 +108,7 @@ cscli simulation disable crowdsecurity/ssh-bf`,
 		DisableAutoGenTag: true,
 		DisableAutoGenTag: true,
 		PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
 		PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
 			if err := csConfig.LoadSimulation(); err != nil {
 			if err := csConfig.LoadSimulation(); err != nil {
-				log.Fatalf(err.Error())
+				log.Fatal(err)
 			}
 			}
 			if csConfig.Cscli == nil {
 			if csConfig.Cscli == nil {
 				return fmt.Errorf("you must configure cli before using simulation")
 				return fmt.Errorf("you must configure cli before using simulation")

+ 3 - 3
cmd/crowdsec-cli/support.go

@@ -160,11 +160,11 @@ func collectAPIStatus(login string, password string, endpoint string, prefix str
 	apiurl, err := url.Parse(endpoint)
 	apiurl, err := url.Parse(endpoint)
 
 
 	if err != nil {
 	if err != nil {
-		return []byte(fmt.Sprintf("cannot parse API URL: %s", err.Error()))
+		return []byte(fmt.Sprintf("cannot parse API URL: %s", err))
 	}
 	}
 	scenarios, err := cwhub.GetInstalledScenariosAsString()
 	scenarios, err := cwhub.GetInstalledScenariosAsString()
 	if err != nil {
 	if err != nil {
-		return []byte(fmt.Sprintf("could not collect scenarios: %s", err.Error()))
+		return []byte(fmt.Sprintf("could not collect scenarios: %s", err))
 	}
 	}
 
 
 	Client, err = apiclient.NewDefaultClient(apiurl,
 	Client, err = apiclient.NewDefaultClient(apiurl,
@@ -172,7 +172,7 @@ func collectAPIStatus(login string, password string, endpoint string, prefix str
 		fmt.Sprintf("crowdsec/%s", cwversion.VersionStr()),
 		fmt.Sprintf("crowdsec/%s", cwversion.VersionStr()),
 		nil)
 		nil)
 	if err != nil {
 	if err != nil {
-		return []byte(fmt.Sprintf("could not init client: %s", err.Error()))
+		return []byte(fmt.Sprintf("could not init client: %s", err))
 	}
 	}
 	t := models.WatcherAuthRequest{
 	t := models.WatcherAuthRequest{
 		MachineID: &login,
 		MachineID: &login,

+ 1 - 1
cmd/crowdsec/api.go

@@ -52,7 +52,7 @@ func serveAPIServer(apiServer *apiserver.APIServer, apiReady chan bool) {
 			defer types.CatchPanic("crowdsec/runAPIServer")
 			defer types.CatchPanic("crowdsec/runAPIServer")
 			log.Debugf("serving API after %s ms", time.Since(crowdsecT0))
 			log.Debugf("serving API after %s ms", time.Since(crowdsecT0))
 			if err := apiServer.Run(apiReady); err != nil {
 			if err := apiServer.Run(apiReady); err != nil {
-				log.Fatalf(err.Error())
+				log.Fatal(err)
 			}
 			}
 		}()
 		}()
 
 

+ 1 - 1
cmd/crowdsec/run_in_svc.go

@@ -40,7 +40,7 @@ func StartRunSvc() error {
 	// Configure logging
 	// Configure logging
 	if err = types.SetDefaultLoggerConfig(cConfig.Common.LogMedia, cConfig.Common.LogDir, *cConfig.Common.LogLevel,
 	if err = types.SetDefaultLoggerConfig(cConfig.Common.LogMedia, cConfig.Common.LogDir, *cConfig.Common.LogLevel,
 		cConfig.Common.LogMaxSize, cConfig.Common.LogMaxFiles, cConfig.Common.LogMaxAge, cConfig.Common.CompressLogs, cConfig.Common.ForceColorLogs); err != nil {
 		cConfig.Common.LogMaxSize, cConfig.Common.LogMaxFiles, cConfig.Common.LogMaxAge, cConfig.Common.CompressLogs, cConfig.Common.ForceColorLogs); err != nil {
-		log.Fatal(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	log.Infof("Crowdsec %s", cwversion.VersionStr())
 	log.Infof("Crowdsec %s", cwversion.VersionStr())

+ 1 - 1
cmd/crowdsec/win_service.go

@@ -58,7 +58,7 @@ func (m *crowdsec_winservice) Execute(args []string, r <-chan svc.ChangeRequest,
 	err := WindowsRun()
 	err := WindowsRun()
 	changes <- svc.Status{State: svc.Stopped}
 	changes <- svc.Status{State: svc.Stopped}
 	if err != nil {
 	if err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 	return
 	return
 }
 }

+ 4 - 4
pkg/acquisition/acquisition.go

@@ -184,11 +184,11 @@ func LoadAcquisitionFromFile(config *csconfig.CrowdsecServiceCfg) ([]DataSource,
 			var idx int
 			var idx int
 			err = dec.Decode(&sub)
 			err = dec.Decode(&sub)
 			if err != nil {
 			if err != nil {
-				if err == io.EOF {
-					log.Tracef("End of yaml file")
-					break
+				if ! errors.Is(err, io.EOF) {
+					return nil, errors.Wrapf(err, "failed to yaml decode %s", acquisFile)
 				}
 				}
-				return nil, errors.Wrapf(err, "failed to yaml decode %s", acquisFile)
+				log.Tracef("End of yaml file")
+				break
 			}
 			}
 
 
 			//for backward compat ('type' was not mandatory, detect it)
 			//for backward compat ('type' was not mandatory, detect it)

+ 4 - 4
pkg/acquisition/modules/kafka/kafka_test.go

@@ -85,18 +85,18 @@ func writeToKafka(w *kafka.Writer, logs []string) {
 func createTopic(topic string, broker string) {
 func createTopic(topic string, broker string) {
 	conn, err := kafka.Dial("tcp", broker)
 	conn, err := kafka.Dial("tcp", broker)
 	if err != nil {
 	if err != nil {
-		panic(err.Error())
+		panic(err)
 	}
 	}
 	defer conn.Close()
 	defer conn.Close()
 
 
 	controller, err := conn.Controller()
 	controller, err := conn.Controller()
 	if err != nil {
 	if err != nil {
-		panic(err.Error())
+		panic(err)
 	}
 	}
 	var controllerConn *kafka.Conn
 	var controllerConn *kafka.Conn
 	controllerConn, err = kafka.Dial("tcp", net.JoinHostPort(controller.Host, strconv.Itoa(controller.Port)))
 	controllerConn, err = kafka.Dial("tcp", net.JoinHostPort(controller.Host, strconv.Itoa(controller.Port)))
 	if err != nil {
 	if err != nil {
-		panic(err.Error())
+		panic(err)
 	}
 	}
 	defer controllerConn.Close()
 	defer controllerConn.Close()
 
 
@@ -110,7 +110,7 @@ func createTopic(topic string, broker string) {
 
 
 	err = controllerConn.CreateTopics(topicConfigs...)
 	err = controllerConn.CreateTopics(topicConfigs...)
 	if err != nil {
 	if err != nil {
-		panic(err.Error())
+		panic(err)
 	}
 	}
 }
 }
 
 

+ 5 - 7
pkg/apiclient/client_http.go

@@ -103,17 +103,15 @@ func (c *ApiClient) Do(ctx context.Context, req *http.Request, v interface{}) (*
 	}
 	}
 
 
 	if v != nil {
 	if v != nil {
-		if w, ok := v.(io.Writer); ok {
-			io.Copy(w, resp.Body)
-		} else {
+		w, ok := v.(io.Writer)
+		if !ok {
 			decErr := json.NewDecoder(resp.Body).Decode(v)
 			decErr := json.NewDecoder(resp.Body).Decode(v)
-			if decErr == io.EOF {
+			if errors.Is(decErr, io.EOF) {
 				decErr = nil // ignore EOF errors caused by empty response body
 				decErr = nil // ignore EOF errors caused by empty response body
 			}
 			}
-			if decErr != nil {
-				err = decErr
-			}
+			return response, decErr
 		}
 		}
+		io.Copy(w, resp.Body)
 	}
 	}
 	return response, err
 	return response, err
 }
 }

+ 1 - 1
pkg/apiclient/decisions_service_test.go

@@ -326,7 +326,7 @@ func TestDecisionsStreamOpts_addQueryParamsToURL(t *testing.T) {
 // 	})
 // 	})
 
 
 // 	if err != nil {
 // 	if err != nil {
-// 		t.Fatalf("new api client: %s", err.Error())
+// 		t.Fatalf("new api client: %s", err)
 // 	}
 // 	}
 
 
 // 	filters := DecisionsDeleteOpts{IPEquals: new(string)}
 // 	filters := DecisionsDeleteOpts{IPEquals: new(string)}

+ 3 - 3
pkg/apiserver/alerts_test.go

@@ -76,7 +76,7 @@ func InitMachineTest() (*gin.Engine, models.WatcherAuthResponse, csconfig.Config
 
 
 	loginResp, err := LoginToTestAPI(router, config)
 	loginResp, err := LoginToTestAPI(router, config)
 	if err != nil {
 	if err != nil {
-		return nil, models.WatcherAuthResponse{}, config, fmt.Errorf("%s", err)
+		return nil, models.WatcherAuthResponse{}, config, err
 	}
 	}
 	return router, loginResp, config, nil
 	return router, loginResp, config, nil
 }
 }
@@ -84,7 +84,7 @@ func InitMachineTest() (*gin.Engine, models.WatcherAuthResponse, csconfig.Config
 func LoginToTestAPI(router *gin.Engine, config csconfig.Config) (models.WatcherAuthResponse, error) {
 func LoginToTestAPI(router *gin.Engine, config csconfig.Config) (models.WatcherAuthResponse, error) {
 	body, err := CreateTestMachine(router)
 	body, err := CreateTestMachine(router)
 	if err != nil {
 	if err != nil {
-		return models.WatcherAuthResponse{}, fmt.Errorf("%s", err)
+		return models.WatcherAuthResponse{}, err
 	}
 	}
 	err = ValidateMachine("test", config.API.Server.DbConfig)
 	err = ValidateMachine("test", config.API.Server.DbConfig)
 	if err != nil {
 	if err != nil {
@@ -99,7 +99,7 @@ func LoginToTestAPI(router *gin.Engine, config csconfig.Config) (models.WatcherA
 	loginResp := models.WatcherAuthResponse{}
 	loginResp := models.WatcherAuthResponse{}
 	err = json.NewDecoder(w.Body).Decode(&loginResp)
 	err = json.NewDecoder(w.Body).Decode(&loginResp)
 	if err != nil {
 	if err != nil {
-		return models.WatcherAuthResponse{}, fmt.Errorf("%s", err)
+		return models.WatcherAuthResponse{}, err
 	}
 	}
 
 
 	return loginResp, nil
 	return loginResp, nil

+ 4 - 4
pkg/apiserver/apiserver.go

@@ -70,10 +70,10 @@ func CustomRecoveryWithWriter() gin.HandlerFunc {
 						errHandlerComplete    = errors.New("http2: request body closed due to handler exiting")
 						errHandlerComplete    = errors.New("http2: request body closed due to handler exiting")
 						errStreamClosed       = errors.New("http2: stream closed")
 						errStreamClosed       = errors.New("http2: stream closed")
 					)
 					)
-					if strErr == errClientDisconnected ||
-						strErr == errClosedBody ||
-						strErr == errHandlerComplete ||
-						strErr == errStreamClosed {
+					if errors.Is(strErr, errClientDisconnected) ||
+						errors.Is(strErr, errClosedBody) ||
+						errors.Is(strErr, errHandlerComplete) ||
+						errors.Is(strErr, errStreamClosed) {
 						brokenPipe = true
 						brokenPipe = true
 					}
 					}
 				}
 				}

+ 2 - 2
pkg/apiserver/apiserver_test.go

@@ -358,7 +358,7 @@ func TestLoggingDebugToFileConfig(t *testing.T) {
 
 
 	// Configure logging
 	// Configure logging
 	if err := types.SetDefaultLoggerConfig(cfg.LogMedia, cfg.LogDir, *cfg.LogLevel, cfg.LogMaxSize, cfg.LogMaxFiles, cfg.LogMaxAge, cfg.CompressLogs, false); err != nil {
 	if err := types.SetDefaultLoggerConfig(cfg.LogMedia, cfg.LogDir, *cfg.LogLevel, cfg.LogMaxSize, cfg.LogMaxFiles, cfg.LogMaxAge, cfg.CompressLogs, false); err != nil {
-		t.Fatal(err.Error())
+		t.Fatal(err)
 	}
 	}
 	api, err := NewServer(&cfg)
 	api, err := NewServer(&cfg)
 	if err != nil {
 	if err != nil {
@@ -415,7 +415,7 @@ func TestLoggingErrorToFileConfig(t *testing.T) {
 
 
 	// Configure logging
 	// Configure logging
 	if err := types.SetDefaultLoggerConfig(cfg.LogMedia, cfg.LogDir, *cfg.LogLevel, cfg.LogMaxSize, cfg.LogMaxFiles, cfg.LogMaxAge, cfg.CompressLogs, false); err != nil {
 	if err := types.SetDefaultLoggerConfig(cfg.LogMedia, cfg.LogDir, *cfg.LogLevel, cfg.LogMaxSize, cfg.LogMaxFiles, cfg.LogMaxAge, cfg.CompressLogs, false); err != nil {
-		t.Fatal(err.Error())
+		t.Fatal(err)
 	}
 	}
 	api, err := NewServer(&cfg)
 	api, err := NewServer(&cfg)
 	if err != nil {
 	if err != nil {

+ 2 - 2
pkg/apiserver/jwt_test.go

@@ -18,7 +18,7 @@ func TestLogin(t *testing.T) {
 
 
 	body, err := CreateTestMachine(router)
 	body, err := CreateTestMachine(router)
 	if err != nil {
 	if err != nil {
-		log.Fatalln(err.Error())
+		log.Fatalln(err)
 	}
 	}
 
 
 	// Login with machine not validated yet
 	// Login with machine not validated yet
@@ -60,7 +60,7 @@ func TestLogin(t *testing.T) {
 	//Validate machine
 	//Validate machine
 	err = ValidateMachine("test", config.API.Server.DbConfig)
 	err = ValidateMachine("test", config.API.Server.DbConfig)
 	if err != nil {
 	if err != nil {
-		log.Fatalln(err.Error())
+		log.Fatalln(err)
 	}
 	}
 
 
 	// Login with invalid password
 	// Login with invalid password

+ 1 - 1
pkg/apiserver/machines_test.go

@@ -150,7 +150,7 @@ func TestCreateMachineAlreadyExist(t *testing.T) {
 
 
 	body, err := CreateTestMachine(router)
 	body, err := CreateTestMachine(router)
 	if err != nil {
 	if err != nil {
-		log.Fatalln(err.Error())
+		log.Fatalln(err)
 	}
 	}
 
 
 	w := httptest.NewRecorder()
 	w := httptest.NewRecorder()

+ 3 - 3
pkg/csconfig/api_test.go

@@ -157,18 +157,18 @@ func TestLoadAPIServer(t *testing.T) {
 
 
 	LogDirFullPath, err := filepath.Abs("./tests")
 	LogDirFullPath, err := filepath.Abs("./tests")
 	if err != nil {
 	if err != nil {
-		t.Fatalf(err.Error())
+		t.Fatal(err)
 	}
 	}
 
 
 	config := &Config{}
 	config := &Config{}
 	fcontent, err := os.ReadFile("./tests/config.yaml")
 	fcontent, err := os.ReadFile("./tests/config.yaml")
 	if err != nil {
 	if err != nil {
-		t.Fatalf(err.Error())
+		t.Fatal(err)
 	}
 	}
 	configData := os.ExpandEnv(string(fcontent))
 	configData := os.ExpandEnv(string(fcontent))
 	err = yaml.UnmarshalStrict([]byte(configData), &config)
 	err = yaml.UnmarshalStrict([]byte(configData), &config)
 	if err != nil {
 	if err != nil {
-		t.Fatalf(err.Error())
+		t.Fatal(err)
 	}
 	}
 	tests := []struct {
 	tests := []struct {
 		name           string
 		name           string

+ 2 - 2
pkg/csconfig/common_test.go

@@ -13,12 +13,12 @@ func TestLoadCommon(t *testing.T) {
 	pidDirPath := "./tests"
 	pidDirPath := "./tests"
 	LogDirFullPath, err := filepath.Abs("./tests/log/")
 	LogDirFullPath, err := filepath.Abs("./tests/log/")
 	if err != nil {
 	if err != nil {
-		t.Fatalf(err.Error())
+		t.Fatal(err)
 	}
 	}
 
 
 	WorkingDirFullPath, err := filepath.Abs("./tests")
 	WorkingDirFullPath, err := filepath.Abs("./tests")
 	if err != nil {
 	if err != nil {
-		t.Fatalf(err.Error())
+		t.Fatal(err)
 	}
 	}
 
 
 	tests := []struct {
 	tests := []struct {

+ 4 - 4
pkg/csconfig/cscli_test.go

@@ -12,22 +12,22 @@ import (
 func TestLoadCSCLI(t *testing.T) {
 func TestLoadCSCLI(t *testing.T) {
 	hubFullPath, err := filepath.Abs("./hub")
 	hubFullPath, err := filepath.Abs("./hub")
 	if err != nil {
 	if err != nil {
-		t.Fatalf(err.Error())
+		t.Fatal(err)
 	}
 	}
 
 
 	dataFullPath, err := filepath.Abs("./data")
 	dataFullPath, err := filepath.Abs("./data")
 	if err != nil {
 	if err != nil {
-		t.Fatalf(err.Error())
+		t.Fatal(err)
 	}
 	}
 
 
 	configDirFullPath, err := filepath.Abs("./tests")
 	configDirFullPath, err := filepath.Abs("./tests")
 	if err != nil {
 	if err != nil {
-		t.Fatalf(err.Error())
+		t.Fatal(err)
 	}
 	}
 
 
 	hubIndexFileFullPath, err := filepath.Abs("./hub/.index.json")
 	hubIndexFileFullPath, err := filepath.Abs("./hub/.index.json")
 	if err != nil {
 	if err != nil {
-		t.Fatalf(err.Error())
+		t.Fatal(err)
 	}
 	}
 
 
 	tests := []struct {
 	tests := []struct {

+ 1 - 1
pkg/csconfig/profiles.go

@@ -42,7 +42,7 @@ func (c *LocalApiServerCfg) LoadProfiles() error {
 		t := ProfileCfg{}
 		t := ProfileCfg{}
 		err = dec.Decode(&t)
 		err = dec.Decode(&t)
 		if err != nil {
 		if err != nil {
-			if err == io.EOF {
+			if errors.Is(err, io.EOF) {
 				break
 				break
 			}
 			}
 			return errors.Wrapf(err, "while decoding %s", c.ProfilesPath)
 			return errors.Wrapf(err, "while decoding %s", c.ProfilesPath)

+ 1 - 1
pkg/csplugin/broker.go

@@ -351,7 +351,7 @@ func ParsePluginConfigFile(path string) ([]PluginConfig, error) {
 		pc := PluginConfig{}
 		pc := PluginConfig{}
 		err = dec.Decode(&pc)
 		err = dec.Decode(&pc)
 		if err != nil {
 		if err != nil {
-			if err == io.EOF {
+			if errors.Is(err, io.EOF) {
 				break
 				break
 			}
 			}
 			return []PluginConfig{}, fmt.Errorf("while decoding %s got error %s", path, err)
 			return []PluginConfig{}, fmt.Errorf("while decoding %s got error %s", path, err)

+ 3 - 3
pkg/cwhub/download.go

@@ -254,10 +254,10 @@ func downloadData(dataFolder string, force bool, reader io.Reader) error {
 		data := &types.DataSet{}
 		data := &types.DataSet{}
 		err = dec.Decode(data)
 		err = dec.Decode(data)
 		if err != nil {
 		if err != nil {
-			if err != io.EOF {
-				return errors.Wrap(err, "while reading file")
+			if errors.Is(err, io.EOF) {
+				break
 			}
 			}
-			break
+			return errors.Wrap(err, "while reading file")
 		}
 		}
 
 
 		download := false
 		download := false

+ 11 - 11
pkg/exprhelpers/exprlib_test.go

@@ -44,7 +44,7 @@ func getDBClient(t *testing.T) *database.Client {
 
 
 func TestVisitor(t *testing.T) {
 func TestVisitor(t *testing.T) {
 	if err := Init(nil); err != nil {
 	if err := Init(nil); err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	tests := []struct {
 	tests := []struct {
@@ -131,12 +131,12 @@ func TestVisitor(t *testing.T) {
 
 
 func TestRegexpInFile(t *testing.T) {
 func TestRegexpInFile(t *testing.T) {
 	if err := Init(nil); err != nil {
 	if err := Init(nil); err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	err := FileInit(TestFolder, "test_data_re.txt", "regex")
 	err := FileInit(TestFolder, "test_data_re.txt", "regex")
 	if err != nil {
 	if err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	tests := []struct {
 	tests := []struct {
@@ -174,11 +174,11 @@ func TestRegexpInFile(t *testing.T) {
 	for _, test := range tests {
 	for _, test := range tests {
 		compiledFilter, err := expr.Compile(test.filter, expr.Env(GetExprEnv(map[string]interface{}{})))
 		compiledFilter, err := expr.Compile(test.filter, expr.Env(GetExprEnv(map[string]interface{}{})))
 		if err != nil {
 		if err != nil {
-			log.Fatalf(err.Error())
+			log.Fatal(err)
 		}
 		}
 		result, err := expr.Run(compiledFilter, GetExprEnv(map[string]interface{}{}))
 		result, err := expr.Run(compiledFilter, GetExprEnv(map[string]interface{}{}))
 		if err != nil {
 		if err != nil {
-			log.Fatalf(err.Error())
+			log.Fatal(err)
 		}
 		}
 		if isOk := assert.Equal(t, test.result, result); !isOk {
 		if isOk := assert.Equal(t, test.result, result); !isOk {
 			t.Fatalf("test '%s' : NOK", test.name)
 			t.Fatalf("test '%s' : NOK", test.name)
@@ -188,7 +188,7 @@ func TestRegexpInFile(t *testing.T) {
 
 
 func TestFileInit(t *testing.T) {
 func TestFileInit(t *testing.T) {
 	if err := Init(nil); err != nil {
 	if err := Init(nil); err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	tests := []struct {
 	tests := []struct {
@@ -226,7 +226,7 @@ func TestFileInit(t *testing.T) {
 	for _, test := range tests {
 	for _, test := range tests {
 		err := FileInit(TestFolder, test.filename, test.types)
 		err := FileInit(TestFolder, test.filename, test.types)
 		if err != nil {
 		if err != nil {
-			log.Fatalf(err.Error())
+			log.Fatal(err)
 		}
 		}
 		if test.types == "string" {
 		if test.types == "string" {
 			if _, ok := dataFile[test.filename]; !ok {
 			if _, ok := dataFile[test.filename]; !ok {
@@ -256,12 +256,12 @@ func TestFileInit(t *testing.T) {
 
 
 func TestFile(t *testing.T) {
 func TestFile(t *testing.T) {
 	if err := Init(nil); err != nil {
 	if err := Init(nil); err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	err := FileInit(TestFolder, "test_data.txt", "string")
 	err := FileInit(TestFolder, "test_data.txt", "string")
 	if err != nil {
 	if err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	tests := []struct {
 	tests := []struct {
@@ -299,11 +299,11 @@ func TestFile(t *testing.T) {
 	for _, test := range tests {
 	for _, test := range tests {
 		compiledFilter, err := expr.Compile(test.filter, expr.Env(GetExprEnv(map[string]interface{}{})))
 		compiledFilter, err := expr.Compile(test.filter, expr.Env(GetExprEnv(map[string]interface{}{})))
 		if err != nil {
 		if err != nil {
-			log.Fatalf(err.Error())
+			log.Fatal(err)
 		}
 		}
 		result, err := expr.Run(compiledFilter, GetExprEnv(map[string]interface{}{}))
 		result, err := expr.Run(compiledFilter, GetExprEnv(map[string]interface{}{}))
 		if err != nil {
 		if err != nil {
-			log.Fatalf(err.Error())
+			log.Fatal(err)
 		}
 		}
 		if isOk := assert.Equal(t, test.result, result); !isOk {
 		if isOk := assert.Equal(t, test.result, result); !isOk {
 			t.Fatalf("test '%s' : NOK", test.name)
 			t.Fatalf("test '%s' : NOK", test.name)

+ 4 - 3
pkg/exprhelpers/jsonextract.go

@@ -2,6 +2,7 @@ package exprhelpers
 
 
 import (
 import (
 	"encoding/json"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"fmt"
 	"strings"
 	"strings"
 
 
@@ -17,7 +18,7 @@ func JsonExtractLib(jsblob string, target ...string) string {
 	)
 	)
 
 
 	if err != nil {
 	if err != nil {
-		if err == jsonparser.KeyPathNotFoundError {
+		if errors.Is(err, jsonparser.KeyPathNotFoundError) {
 			log.Debugf("%+v doesn't exist", target)
 			log.Debugf("%+v doesn't exist", target)
 			return ""
 			return ""
 		}
 		}
@@ -39,7 +40,7 @@ func JsonExtractUnescape(jsblob string, target ...string) string {
 	)
 	)
 
 
 	if err != nil {
 	if err != nil {
-		if err == jsonparser.KeyPathNotFoundError {
+		if errors.Is(err, jsonparser.KeyPathNotFoundError) {
 			log.Debugf("%+v doesn't exist", target)
 			log.Debugf("%+v doesn't exist", target)
 			return ""
 			return ""
 		}
 		}
@@ -74,7 +75,7 @@ func jsonExtractType(jsblob string, target string, t jsonparser.ValueType) ([]by
 	)
 	)
 
 
 	if err != nil {
 	if err != nil {
-		if err == jsonparser.KeyPathNotFoundError {
+		if errors.Is(err, jsonparser.KeyPathNotFoundError) {
 			log.Debugf("Key %+v doesn't exist", target)
 			log.Debugf("Key %+v doesn't exist", target)
 			return nil, fmt.Errorf("key %s does not exist", target)
 			return nil, fmt.Errorf("key %s does not exist", target)
 		}
 		}

+ 8 - 8
pkg/exprhelpers/jsonextract_test.go

@@ -9,12 +9,12 @@ import (
 
 
 func TestJsonExtract(t *testing.T) {
 func TestJsonExtract(t *testing.T) {
 	if err := Init(nil); err != nil {
 	if err := Init(nil); err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	err := FileInit(TestFolder, "test_data_re.txt", "regex")
 	err := FileInit(TestFolder, "test_data_re.txt", "regex")
 	if err != nil {
 	if err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	tests := []struct {
 	tests := []struct {
@@ -55,12 +55,12 @@ func TestJsonExtract(t *testing.T) {
 }
 }
 func TestJsonExtractUnescape(t *testing.T) {
 func TestJsonExtractUnescape(t *testing.T) {
 	if err := Init(nil); err != nil {
 	if err := Init(nil); err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	err := FileInit(TestFolder, "test_data_re.txt", "regex")
 	err := FileInit(TestFolder, "test_data_re.txt", "regex")
 	if err != nil {
 	if err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	tests := []struct {
 	tests := []struct {
@@ -95,12 +95,12 @@ func TestJsonExtractUnescape(t *testing.T) {
 
 
 func TestJsonExtractSlice(t *testing.T) {
 func TestJsonExtractSlice(t *testing.T) {
 	if err := Init(nil); err != nil {
 	if err := Init(nil); err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	err := FileInit(TestFolder, "test_data_re.txt", "regex")
 	err := FileInit(TestFolder, "test_data_re.txt", "regex")
 	if err != nil {
 	if err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	tests := []struct {
 	tests := []struct {
@@ -146,12 +146,12 @@ func TestJsonExtractSlice(t *testing.T) {
 
 
 func TestJsonExtractObject(t *testing.T) {
 func TestJsonExtractObject(t *testing.T) {
 	if err := Init(nil); err != nil {
 	if err := Init(nil); err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	err := FileInit(TestFolder, "test_data_re.txt", "regex")
 	err := FileInit(TestFolder, "test_data_re.txt", "regex")
 	if err != nil {
 	if err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	tests := []struct {
 	tests := []struct {

+ 2 - 2
pkg/exprhelpers/xml_test.go

@@ -9,7 +9,7 @@ import (
 
 
 func TestXMLGetAttributeValue(t *testing.T) {
 func TestXMLGetAttributeValue(t *testing.T) {
 	if err := Init(nil); err != nil {
 	if err := Init(nil); err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	tests := []struct {
 	tests := []struct {
@@ -68,7 +68,7 @@ func TestXMLGetAttributeValue(t *testing.T) {
 }
 }
 func TestXMLGetNodeValue(t *testing.T) {
 func TestXMLGetNodeValue(t *testing.T) {
 	if err := Init(nil); err != nil {
 	if err := Init(nil); err != nil {
-		log.Fatalf(err.Error())
+		log.Fatal(err)
 	}
 	}
 
 
 	tests := []struct {
 	tests := []struct {

+ 2 - 1
pkg/leakybucket/buckets_test.go

@@ -3,6 +3,7 @@ package leakybucket
 import (
 import (
 	"bytes"
 	"bytes"
 	"encoding/json"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"fmt"
 	"html/template"
 	"html/template"
 	"io"
 	"io"
@@ -153,7 +154,7 @@ func testFile(t *testing.T, file string, bs string, holders []BucketFactory, res
 	tf := TestFile{}
 	tf := TestFile{}
 	err = dec.Decode(&tf)
 	err = dec.Decode(&tf)
 	if err != nil {
 	if err != nil {
-		if err != io.EOF {
+		if errors.Is(err, io.EOF) {
 			t.Errorf("Failed to load testfile '%s' yaml error : %v", file, err)
 			t.Errorf("Failed to load testfile '%s' yaml error : %v", file, err)
 			return false
 			return false
 		}
 		}

+ 2 - 1
pkg/leakybucket/manager_load.go

@@ -2,6 +2,7 @@ package leakybucket
 
 
 import (
 import (
 	"encoding/json"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"fmt"
 	"io"
 	"io"
 	"os"
 	"os"
@@ -169,7 +170,7 @@ func LoadBuckets(cscfg *csconfig.CrowdsecServiceCfg, files []string, tomb *tomb.
 			bucketFactory := BucketFactory{}
 			bucketFactory := BucketFactory{}
 			err = dec.Decode(&bucketFactory)
 			err = dec.Decode(&bucketFactory)
 			if err != nil {
 			if err != nil {
-				if err != io.EOF {
+				if !errors.Is(err, io.EOF) {
 					log.Errorf("Bad yaml in %s : %v", f, err)
 					log.Errorf("Bad yaml in %s : %v", f, err)
 					return nil, nil, fmt.Errorf("bad yaml in %s : %v", f, err)
 					return nil, nil, fmt.Errorf("bad yaml in %s : %v", f, err)
 				}
 				}

+ 2 - 2
pkg/metabase/container.go

@@ -155,7 +155,7 @@ func RemoveContainer(name string) error {
 	ctx := context.Background()
 	ctx := context.Background()
 	log.Printf("Removing docker metabase %s", name)
 	log.Printf("Removing docker metabase %s", name)
 	if err := cli.ContainerRemove(ctx, name, types.ContainerRemoveOptions{}); err != nil {
 	if err := cli.ContainerRemove(ctx, name, types.ContainerRemoveOptions{}); err != nil {
-		return fmt.Errorf("failed remove container %s : %s", name, err)
+		return fmt.Errorf("failed to remove container %s : %s", name, err)
 	}
 	}
 	return nil
 	return nil
 }
 }
@@ -168,7 +168,7 @@ func RemoveImageContainer() error {
 	ctx := context.Background()
 	ctx := context.Background()
 	log.Printf("Removing docker image '%s'", metabaseImage)
 	log.Printf("Removing docker image '%s'", metabaseImage)
 	if _, err := cli.ImageRemove(ctx, metabaseImage, types.ImageRemoveOptions{}); err != nil {
 	if _, err := cli.ImageRemove(ctx, metabaseImage, types.ImageRemoveOptions{}); err != nil {
-		return fmt.Errorf("failed remove image container %s : %s", metabaseImage, err)
+		return fmt.Errorf("failed to remove image container %s : %s", metabaseImage, err)
 	}
 	}
 	return nil
 	return nil
 }
 }

+ 1 - 1
pkg/metabase/metabase.go

@@ -367,7 +367,7 @@ func (m *Metabase) ExtractDatabase(buf *bytes.Reader) error {
 			return fmt.Errorf("while opening zip content %s : %s", f.Name, err)
 			return fmt.Errorf("while opening zip content %s : %s", f.Name, err)
 		}
 		}
 		written, err := io.Copy(tfd, rc)
 		written, err := io.Copy(tfd, rc)
-		if err == io.EOF {
+		if errors.Is(err, io.EOF) {
 			log.Printf("files finished ok")
 			log.Printf("files finished ok")
 		} else if err != nil {
 		} else if err != nil {
 			return fmt.Errorf("while copying content to %s : %s", tfname, err)
 			return fmt.Errorf("while copying content to %s : %s", tfname, err)

+ 1 - 1
pkg/parser/node.go

@@ -420,7 +420,7 @@ func (n *Node) compile(pctx *UnixParserCtx, ectx EnricherCtx) error {
 	for _, pattern := range n.SubGroks {
 	for _, pattern := range n.SubGroks {
 		n.Logger.Tracef("Adding subpattern '%s' : '%s'", pattern.Key, pattern.Value)
 		n.Logger.Tracef("Adding subpattern '%s' : '%s'", pattern.Key, pattern.Value)
 		if err := pctx.Grok.Add(pattern.Key.(string), pattern.Value.(string)); err != nil {
 		if err := pctx.Grok.Add(pattern.Key.(string), pattern.Value.(string)); err != nil {
-			if err == grokky.ErrAlreadyExist {
+			if errors.Is(err, grokky.ErrAlreadyExist) {
 				n.Logger.Warningf("grok '%s' already registred", pattern.Key)
 				n.Logger.Warningf("grok '%s' already registred", pattern.Key)
 				continue
 				continue
 			}
 			}

+ 2 - 1
pkg/parser/parsing_test.go

@@ -2,6 +2,7 @@ package parser
 
 
 import (
 import (
 	"bytes"
 	"bytes"
+	"errors"
 	"fmt"
 	"fmt"
 	"html/template"
 	"html/template"
 	"io"
 	"io"
@@ -182,7 +183,7 @@ func loadTestFile(file string) []TestFile {
 		tf := TestFile{}
 		tf := TestFile{}
 		err := dec.Decode(&tf)
 		err := dec.Decode(&tf)
 		if err != nil {
 		if err != nil {
-			if err == io.EOF {
+			if errors.Is(err, io.EOF) {
 				break
 				break
 			}
 			}
 			log.Fatalf("Failed to load testfile '%s' yaml error : %v", file, err)
 			log.Fatalf("Failed to load testfile '%s' yaml error : %v", file, err)

+ 3 - 4
pkg/parser/stage.go

@@ -7,8 +7,7 @@ package parser
 */
 */
 
 
 import (
 import (
-	//"fmt"
-
+	"errors"
 	"fmt"
 	"fmt"
 	"io"
 	"io"
 	_ "net/http/pprof"
 	_ "net/http/pprof"
@@ -68,7 +67,7 @@ func LoadStages(stageFiles []Stagefile, pctx *UnixParserCtx, ectx EnricherCtx) (
 			node.OnSuccess = "continue" //default behavior is to continue
 			node.OnSuccess = "continue" //default behavior is to continue
 			err = dec.Decode(&node)
 			err = dec.Decode(&node)
 			if err != nil {
 			if err != nil {
-				if err == io.EOF {
+				if errors.Is(err, io.EOF) {
 					log.Tracef("End of yaml file")
 					log.Tracef("End of yaml file")
 					break
 					break
 				}
 				}
@@ -115,7 +114,7 @@ func LoadStages(stageFiles []Stagefile, pctx *UnixParserCtx, ectx EnricherCtx) (
 				for _, data := range node.Data {
 				for _, data := range node.Data {
 					err = exprhelpers.FileInit(pctx.DataFolder, data.DestPath, data.Type)
 					err = exprhelpers.FileInit(pctx.DataFolder, data.DestPath, data.Type)
 					if err != nil {
 					if err != nil {
-						log.Errorf(err.Error())
+						log.Error(err)
 					}
 					}
 				}
 				}
 			}
 			}