simplify err.Error() to err when used in printf context (#1603)
This commit is contained in:
parent
3c6834fc18
commit
628d7be1d8
32 changed files with 90 additions and 90 deletions
|
@ -306,12 +306,12 @@ cscli alerts list --type ban`,
|
|||
}
|
||||
alerts, _, err := Client.Alerts.List(context.Background(), alertListFilter)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to list alerts : %v", err.Error())
|
||||
log.Fatalf("Unable to list alerts : %v", err)
|
||||
}
|
||||
|
||||
err = AlertsToTable(alerts, printMachine)
|
||||
if err != nil {
|
||||
log.Fatalf("unable to list alerts : %v", err.Error())
|
||||
log.Fatalf("unable to list alerts : %v", err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ cscli alerts delete -s crowdsecurity/ssh-bf"`,
|
|||
}
|
||||
alerts, _, err := Client.Alerts.Delete(context.Background(), alertDeleteFilter)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to delete alerts : %v", err.Error())
|
||||
log.Fatalf("Unable to delete alerts : %v", err)
|
||||
}
|
||||
log.Infof("%s alert(s) deleted", alerts.NbDeleted)
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ func NewCapiCmd() *cobra.Command {
|
|||
}
|
||||
scenarios, err := cwhub.GetInstalledScenariosAsString()
|
||||
if err != nil {
|
||||
log.Fatalf("failed to get scenarios : %s", err.Error())
|
||||
log.Fatalf("failed to get scenarios : %s", err)
|
||||
}
|
||||
if len(scenarios) == 0 {
|
||||
log.Fatalf("no scenarios installed, abort")
|
||||
|
|
|
@ -88,7 +88,7 @@ After running this command your will need to validate the enrollment in the weba
|
|||
|
||||
scenarios, err := cwhub.GetInstalledScenariosAsString()
|
||||
if err != nil {
|
||||
log.Fatalf("failed to get scenarios : %s", err.Error())
|
||||
log.Fatalf("failed to get scenarios : %s", err)
|
||||
}
|
||||
|
||||
if len(scenarios) == 0 {
|
||||
|
|
|
@ -269,12 +269,12 @@ cscli decisions list -t ban
|
|||
|
||||
alerts, _, err := Client.Alerts.List(context.Background(), filter)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to list decisions : %v", err.Error())
|
||||
log.Fatalf("Unable to list decisions : %v", err)
|
||||
}
|
||||
|
||||
err = DecisionsToTable(alerts, printMachine)
|
||||
if err != nil {
|
||||
log.Fatalf("unable to list decisions : %v", err.Error())
|
||||
log.Fatalf("unable to list decisions : %v", err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -467,12 +467,12 @@ cscli decisions delete --type captcha
|
|||
if delDecisionId == "" {
|
||||
decisions, _, err = Client.Decisions.Delete(context.Background(), delFilter)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to delete decisions : %v", err.Error())
|
||||
log.Fatalf("Unable to delete decisions : %v", err)
|
||||
}
|
||||
} else {
|
||||
decisions, _, err = Client.Decisions.DeleteOne(context.Background(), delDecisionId)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to delete decision : %v", err.Error())
|
||||
log.Fatalf("Unable to delete decision : %v", err)
|
||||
}
|
||||
}
|
||||
log.Infof("%s decision(s) deleted", decisions.NbDeleted)
|
||||
|
|
|
@ -301,7 +301,7 @@ cscli hubtest create my-scenario-test --parsers crowdsecurity/nginx --scenarios
|
|||
}
|
||||
jsonStr, err := json.Marshal(jsonResult)
|
||||
if err != nil {
|
||||
log.Fatalf("unable to json test result: %s", err.Error())
|
||||
log.Fatalf("unable to json test result: %s", err)
|
||||
}
|
||||
fmt.Println(string(jsonStr))
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ Keep in mind the machine needs to be validated by an administrator on LAPI side
|
|||
}
|
||||
scenarios, err := cwhub.GetInstalledScenariosAsString()
|
||||
if err != nil {
|
||||
log.Fatalf("failed to get scenarios : %s", err.Error())
|
||||
log.Fatalf("failed to get scenarios : %s", err)
|
||||
}
|
||||
|
||||
Client, err = apiclient.NewDefaultClient(apiurl,
|
||||
|
|
|
@ -128,7 +128,7 @@ It is meant to allow you to manage bans, parsers/scenarios/etc, api and generall
|
|||
DisableAutoGenTag: true,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if err := doc.GenMarkdownTreeCustom(rootCmd, "./doc/", prepender, linkHandler); err != nil {
|
||||
log.Fatalf("Failed to generate cobra doc: %s", err.Error())
|
||||
log.Fatalf("Failed to generate cobra doc: %s", err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ func enableGlobalSimulation() error {
|
|||
csConfig.Cscli.SimulationConfig.Exclusions = []string{}
|
||||
|
||||
if err := dumpSimulationFile(); err != nil {
|
||||
log.Fatalf("unable to dump simulation file: %s", err.Error())
|
||||
log.Fatalf("unable to dump simulation file: %s", err)
|
||||
}
|
||||
|
||||
log.Printf("global simulation: enabled")
|
||||
|
@ -173,11 +173,11 @@ cscli simulation disable crowdsecurity/ssh-bf`,
|
|||
log.Printf("simulation mode for '%s' enabled", scenario)
|
||||
}
|
||||
if err := dumpSimulationFile(); err != nil {
|
||||
log.Fatalf("simulation enable: %s", err.Error())
|
||||
log.Fatalf("simulation enable: %s", err)
|
||||
}
|
||||
} else if forceGlobalSimulation {
|
||||
if err := enableGlobalSimulation(); err != nil {
|
||||
log.Fatalf("unable to enable global simulation mode : %s", err.Error())
|
||||
log.Fatalf("unable to enable global simulation mode : %s", err)
|
||||
}
|
||||
} else {
|
||||
printHelp(cmd)
|
||||
|
@ -217,11 +217,11 @@ cscli simulation disable crowdsecurity/ssh-bf`,
|
|||
log.Printf("simulation mode for '%s' disabled", scenario)
|
||||
}
|
||||
if err := dumpSimulationFile(); err != nil {
|
||||
log.Fatalf("simulation disable: %s", err.Error())
|
||||
log.Fatalf("simulation disable: %s", err)
|
||||
}
|
||||
} else if forceGlobalSimulation {
|
||||
if err := disableGlobalSimulation(); err != nil {
|
||||
log.Fatalf("unable to disable global simulation mode : %s", err.Error())
|
||||
log.Fatalf("unable to disable global simulation mode : %s", err)
|
||||
}
|
||||
} else {
|
||||
printHelp(cmd)
|
||||
|
|
|
@ -182,7 +182,7 @@ wowo: ajsajasjas
|
|||
t.Fatalf("expected error %s, got none", test.ExpectedError)
|
||||
}
|
||||
if !strings.Contains(err.Error(), test.ExpectedError) {
|
||||
t.Fatalf("%s : expected error '%s' in '%s'", test.TestName, test.ExpectedError, err.Error())
|
||||
t.Fatalf("%s : expected error '%s' in '%s'", test.TestName, test.ExpectedError, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ func TestLoadAcquisitionFromFile(t *testing.T) {
|
|||
t.Fatalf("expected error %s, got none", test.ExpectedError)
|
||||
}
|
||||
if !strings.Contains(err.Error(), test.ExpectedError) {
|
||||
t.Fatalf("%s : expected error '%s' in '%s'", test.TestName, test.ExpectedError, err.Error())
|
||||
t.Fatalf("%s : expected error '%s' in '%s'", test.TestName, test.ExpectedError, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
@ -469,7 +469,7 @@ func TestStartAcquisitionTailError(t *testing.T) {
|
|||
|
||||
go func() {
|
||||
if err := StartAcquisition(sources, out, &acquisTomb); err != nil && err.Error() != "got error (tomb)" {
|
||||
t.Errorf("expected error, got '%s'", err.Error())
|
||||
t.Errorf("expected error, got '%s'", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -431,7 +431,7 @@ stream_name: test_stream`),
|
|||
err = cw.Configure(test.config, dbgLogger)
|
||||
if err != nil && test.expectedCfgErr != "" {
|
||||
if !strings.Contains(err.Error(), test.expectedCfgErr) {
|
||||
t.Fatalf("%s expected error '%s' got error '%s'", test.name, test.expectedCfgErr, err.Error())
|
||||
t.Fatalf("%s expected error '%s' got error '%s'", test.name, test.expectedCfgErr, err)
|
||||
}
|
||||
log.Debugf("got expected error : %s", err)
|
||||
continue
|
||||
|
@ -458,7 +458,7 @@ stream_name: test_stream`),
|
|||
dbgLogger.Infof("acquis done")
|
||||
|
||||
if err != nil && test.expectedStartErr != "" && !strings.Contains(err.Error(), test.expectedStartErr) {
|
||||
t.Fatalf("%s expected error '%s' got '%s'", test.name, test.expectedStartErr, err.Error())
|
||||
t.Fatalf("%s expected error '%s' got '%s'", test.name, test.expectedStartErr, err)
|
||||
} else if err != nil && test.expectedStartErr == "" {
|
||||
t.Fatalf("%s unexpected error '%s'", test.name, err)
|
||||
} else if err == nil && test.expectedStartErr != "" {
|
||||
|
@ -577,7 +577,7 @@ stream_name: test_stream`),
|
|||
err = cw.Configure(test.config, dbgLogger)
|
||||
if err != nil && test.expectedCfgErr != "" {
|
||||
if !strings.Contains(err.Error(), test.expectedCfgErr) {
|
||||
t.Fatalf("%s expected error '%s' got error '%s'", test.name, test.expectedCfgErr, err.Error())
|
||||
t.Fatalf("%s expected error '%s' got error '%s'", test.name, test.expectedCfgErr, err)
|
||||
}
|
||||
log.Debugf("got expected error : %s", err)
|
||||
continue
|
||||
|
@ -598,7 +598,7 @@ stream_name: test_stream`),
|
|||
err = cw.OneShotAcquisition(out, &tmb)
|
||||
}
|
||||
if err != nil && test.expectedStartErr != "" && !strings.Contains(err.Error(), test.expectedStartErr) {
|
||||
t.Fatalf("%s expected error '%s' got '%s'", test.name, test.expectedStartErr, err.Error())
|
||||
t.Fatalf("%s expected error '%s' got '%s'", test.name, test.expectedStartErr, err)
|
||||
} else if err != nil && test.expectedStartErr == "" {
|
||||
t.Fatalf("%s unexpected error '%s'", test.name, err)
|
||||
} else if err == nil && test.expectedStartErr != "" {
|
||||
|
@ -655,7 +655,7 @@ func TestConfigureByDSN(t *testing.T) {
|
|||
err = cw.ConfigureByDSN(test.dsn, test.labels, dbgLogger)
|
||||
if err != nil && test.expectedCfgErr != "" {
|
||||
if !strings.Contains(err.Error(), test.expectedCfgErr) {
|
||||
t.Fatalf("%s expected error '%s' got error '%s'", test.name, test.expectedCfgErr, err.Error())
|
||||
t.Fatalf("%s expected error '%s' got error '%s'", test.name, test.expectedCfgErr, err)
|
||||
}
|
||||
log.Debugf("got expected error : %s", err)
|
||||
continue
|
||||
|
@ -787,7 +787,7 @@ func TestOneShotAcquisition(t *testing.T) {
|
|||
err = cw.ConfigureByDSN(test.dsn, map[string]string{"type": "test"}, dbgLogger)
|
||||
if err != nil && test.expectedCfgErr != "" {
|
||||
if !strings.Contains(err.Error(), test.expectedCfgErr) {
|
||||
t.Fatalf("%s expected error '%s' got error '%s'", test.name, test.expectedCfgErr, err.Error())
|
||||
t.Fatalf("%s expected error '%s' got error '%s'", test.name, test.expectedCfgErr, err)
|
||||
}
|
||||
log.Debugf("got expected error : %s", err)
|
||||
continue
|
||||
|
@ -814,7 +814,7 @@ func TestOneShotAcquisition(t *testing.T) {
|
|||
dbgLogger.Infof("acquis done")
|
||||
|
||||
if err != nil && test.expectedStartErr != "" && !strings.Contains(err.Error(), test.expectedStartErr) {
|
||||
t.Fatalf("%s expected error '%s' got '%s'", test.name, test.expectedStartErr, err.Error())
|
||||
t.Fatalf("%s expected error '%s' got '%s'", test.name, test.expectedStartErr, err)
|
||||
} else if err != nil && test.expectedStartErr == "" {
|
||||
t.Fatalf("%s unexpected error '%s'", test.name, err)
|
||||
} else if err == nil && test.expectedStartErr != "" {
|
||||
|
|
|
@ -413,7 +413,7 @@ func (d *DockerSource) WatchContainer(monitChan chan *ContainerConfig, deleteCha
|
|||
delete(d.runningContainerState, idx)
|
||||
}
|
||||
} else {
|
||||
log.Errorf("container list err: %s", err.Error())
|
||||
log.Errorf("container list err: %s", err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -29,10 +29,10 @@ func TestPri(t *testing.T) {
|
|||
if err != nil {
|
||||
if test.expectedErr != "" {
|
||||
if err.Error() != test.expectedErr {
|
||||
t.Errorf("expected error %s, got %s", test.expectedErr, err.Error())
|
||||
t.Errorf("expected error %s, got %s", test.expectedErr, err)
|
||||
}
|
||||
} else {
|
||||
t.Errorf("unexpected error: %s", err.Error())
|
||||
t.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
} else {
|
||||
if test.expectedErr != "" {
|
||||
|
@ -75,10 +75,10 @@ func TestTimestamp(t *testing.T) {
|
|||
if err != nil {
|
||||
if test.expectedErr != "" {
|
||||
if err.Error() != test.expectedErr {
|
||||
t.Errorf("expected error %s, got %s", test.expectedErr, err.Error())
|
||||
t.Errorf("expected error %s, got %s", test.expectedErr, err)
|
||||
}
|
||||
} else {
|
||||
t.Errorf("unexpected error: %s", err.Error())
|
||||
t.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
} else {
|
||||
if test.expectedErr != "" {
|
||||
|
@ -130,10 +130,10 @@ func TestHostname(t *testing.T) {
|
|||
if err != nil {
|
||||
if test.expectedErr != "" {
|
||||
if err.Error() != test.expectedErr {
|
||||
t.Errorf("expected error %s, got %s", test.expectedErr, err.Error())
|
||||
t.Errorf("expected error %s, got %s", test.expectedErr, err)
|
||||
}
|
||||
} else {
|
||||
t.Errorf("unexpected error: %s", err.Error())
|
||||
t.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
} else {
|
||||
if test.expectedErr != "" {
|
||||
|
@ -172,10 +172,10 @@ func TestTag(t *testing.T) {
|
|||
if err != nil {
|
||||
if test.expectedErr != "" {
|
||||
if err.Error() != test.expectedErr {
|
||||
t.Errorf("expected error %s, got %s", test.expectedErr, err.Error())
|
||||
t.Errorf("expected error %s, got %s", test.expectedErr, err)
|
||||
}
|
||||
} else {
|
||||
t.Errorf("unexpected error: %s", err.Error())
|
||||
t.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
} else {
|
||||
if test.expectedErr != "" {
|
||||
|
@ -215,10 +215,10 @@ func TestMessage(t *testing.T) {
|
|||
if err != nil {
|
||||
if test.expectedErr != "" {
|
||||
if err.Error() != test.expectedErr {
|
||||
t.Errorf("expected error %s, got %s", test.expectedErr, err.Error())
|
||||
t.Errorf("expected error %s, got %s", test.expectedErr, err)
|
||||
}
|
||||
} else {
|
||||
t.Errorf("unexpected error: %s", err.Error())
|
||||
t.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
} else {
|
||||
if test.expectedErr != "" {
|
||||
|
@ -336,10 +336,10 @@ func TestParse(t *testing.T) {
|
|||
if err != nil {
|
||||
if test.expectedErr != "" {
|
||||
if err.Error() != test.expectedErr {
|
||||
t.Errorf("expected error '%s', got '%s'", test.expectedErr, err.Error())
|
||||
t.Errorf("expected error '%s', got '%s'", test.expectedErr, err)
|
||||
}
|
||||
} else {
|
||||
t.Errorf("unexpected error: '%s'", err.Error())
|
||||
t.Errorf("unexpected error: '%s'", err)
|
||||
}
|
||||
} else {
|
||||
if test.expectedErr != "" {
|
||||
|
|
|
@ -29,10 +29,10 @@ func TestPri(t *testing.T) {
|
|||
if err != nil {
|
||||
if test.expectedErr != "" {
|
||||
if err.Error() != test.expectedErr {
|
||||
t.Errorf("expected error %s, got %s", test.expectedErr, err.Error())
|
||||
t.Errorf("expected error %s, got %s", test.expectedErr, err)
|
||||
}
|
||||
} else {
|
||||
t.Errorf("unexpected error: %s", err.Error())
|
||||
t.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
} else {
|
||||
if test.expectedErr != "" {
|
||||
|
@ -84,10 +84,10 @@ func TestHostname(t *testing.T) {
|
|||
if err != nil {
|
||||
if test.expectedErr != "" {
|
||||
if err.Error() != test.expectedErr {
|
||||
t.Errorf("expected error %s, got %s", test.expectedErr, err.Error())
|
||||
t.Errorf("expected error %s, got %s", test.expectedErr, err)
|
||||
}
|
||||
} else {
|
||||
t.Errorf("unexpected error: %s", err.Error())
|
||||
t.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
} else {
|
||||
if test.expectedErr != "" {
|
||||
|
@ -232,10 +232,10 @@ func TestParse(t *testing.T) {
|
|||
if err != nil {
|
||||
if test.expectedErr != "" {
|
||||
if err.Error() != test.expectedErr {
|
||||
t.Errorf("expected error '%s', got '%s'", test.expectedErr, err.Error())
|
||||
t.Errorf("expected error '%s', got '%s'", test.expectedErr, err)
|
||||
}
|
||||
} else {
|
||||
t.Errorf("unexpected error: '%s'", err.Error())
|
||||
t.Errorf("unexpected error: '%s'", err)
|
||||
}
|
||||
} else {
|
||||
if test.expectedErr != "" {
|
||||
|
|
|
@ -60,7 +60,7 @@ func TestApiAuth(t *testing.T) {
|
|||
|
||||
newcli, err = NewDefaultClient(apiURL, "v1", "toto", auth.Client())
|
||||
if err != nil {
|
||||
log.Fatalf("new api client: %s", err.Error())
|
||||
log.Fatalf("new api client: %s", err)
|
||||
}
|
||||
|
||||
_, resp, err = newcli.Decisions.List(context.Background(), alert)
|
||||
|
@ -74,7 +74,7 @@ func TestApiAuth(t *testing.T) {
|
|||
auth = &APIKeyTransport{}
|
||||
newcli, err = NewDefaultClient(apiURL, "v1", "toto", auth.Client())
|
||||
if err != nil {
|
||||
log.Fatalf("new api client: %s", err.Error())
|
||||
log.Fatalf("new api client: %s", err)
|
||||
}
|
||||
|
||||
_, resp, err = newcli.Decisions.List(context.Background(), alert)
|
||||
|
|
|
@ -29,7 +29,7 @@ func TestNewRequestInvalid(t *testing.T) {
|
|||
VersionPrefix: "v1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("new api client: %s", err.Error())
|
||||
t.Fatalf("new api client: %s", err)
|
||||
}
|
||||
/*mock login*/
|
||||
mux.HandleFunc("/watchers/login", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -62,7 +62,7 @@ func TestNewRequestTimeout(t *testing.T) {
|
|||
VersionPrefix: "v1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("new api client: %s", err.Error())
|
||||
t.Fatalf("new api client: %s", err)
|
||||
}
|
||||
/*mock login*/
|
||||
mux.HandleFunc("/watchers/login", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
@ -56,7 +56,7 @@ func TestNewClientOk(t *testing.T) {
|
|||
VersionPrefix: "v1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("new api client: %s", err.Error())
|
||||
t.Fatalf("new api client: %s", err)
|
||||
}
|
||||
/*mock login*/
|
||||
mux.HandleFunc("/watchers/login", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -93,7 +93,7 @@ func TestNewClientKo(t *testing.T) {
|
|||
VersionPrefix: "v1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("new api client: %s", err.Error())
|
||||
t.Fatalf("new api client: %s", err)
|
||||
}
|
||||
/*mock login*/
|
||||
mux.HandleFunc("/watchers/login", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -120,7 +120,7 @@ func TestNewDefaultClient(t *testing.T) {
|
|||
}
|
||||
client, err := NewDefaultClient(apiURL, "/v1", "", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("new api client: %s", err.Error())
|
||||
t.Fatalf("new api client: %s", err)
|
||||
}
|
||||
mux.HandleFunc("/alerts", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
|
|
|
@ -30,12 +30,12 @@ func SetupLAPITest(t *testing.T) LAPI {
|
|||
t.Helper()
|
||||
router, loginResp, config, err := InitMachineTest()
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
APIKey, err := CreateTestBouncer(config.API.Server.DbConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("%s", err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
return LAPI{
|
||||
|
@ -76,7 +76,7 @@ func InitMachineTest() (*gin.Engine, models.WatcherAuthResponse, csconfig.Config
|
|||
|
||||
loginResp, err := LoginToTestAPI(router, config)
|
||||
if err != nil {
|
||||
return nil, models.WatcherAuthResponse{}, config, fmt.Errorf("%s", err.Error())
|
||||
return nil, models.WatcherAuthResponse{}, config, fmt.Errorf("%s", err)
|
||||
}
|
||||
return router, loginResp, config, nil
|
||||
}
|
||||
|
@ -84,11 +84,11 @@ func InitMachineTest() (*gin.Engine, models.WatcherAuthResponse, csconfig.Config
|
|||
func LoginToTestAPI(router *gin.Engine, config csconfig.Config) (models.WatcherAuthResponse, error) {
|
||||
body, err := CreateTestMachine(router)
|
||||
if err != nil {
|
||||
return models.WatcherAuthResponse{}, fmt.Errorf("%s", err.Error())
|
||||
return models.WatcherAuthResponse{}, fmt.Errorf("%s", err)
|
||||
}
|
||||
err = ValidateMachine("test", config.API.Server.DbConfig)
|
||||
if err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
@ -99,7 +99,7 @@ func LoginToTestAPI(router *gin.Engine, config csconfig.Config) (models.WatcherA
|
|||
loginResp := models.WatcherAuthResponse{}
|
||||
err = json.NewDecoder(w.Body).Decode(&loginResp)
|
||||
if err != nil {
|
||||
return models.WatcherAuthResponse{}, fmt.Errorf("%s", err.Error())
|
||||
return models.WatcherAuthResponse{}, fmt.Errorf("%s", err)
|
||||
}
|
||||
|
||||
return loginResp, nil
|
||||
|
@ -153,14 +153,14 @@ func TestCreateAlertChannels(t *testing.T) {
|
|||
|
||||
apiServer, config, err := NewAPIServer()
|
||||
if err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
log.Fatalln(err)
|
||||
}
|
||||
apiServer.controller.PluginChannel = make(chan csplugin.ProfileAlert)
|
||||
apiServer.InitController()
|
||||
|
||||
loginResp, err := LoginToTestAPI(apiServer.router, config)
|
||||
if err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
log.Fatalln(err)
|
||||
}
|
||||
lapi := LAPI{router: apiServer.router, loginResp: loginResp}
|
||||
|
||||
|
@ -427,19 +427,19 @@ func TestDeleteAlertTrustedIPS(t *testing.T) {
|
|||
cfg.API.Server.ListenURI = "::8080"
|
||||
server, err := NewServer(cfg.API.Server)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = server.InitController()
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
log.Fatal(err)
|
||||
}
|
||||
router, err := server.Router()
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
log.Fatal(err)
|
||||
}
|
||||
loginResp, err := LoginToTestAPI(router, cfg)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
log.Fatal(err)
|
||||
}
|
||||
lapi := LAPI{
|
||||
router: router,
|
||||
|
|
|
@ -564,7 +564,7 @@ func (a *apic) SendMetrics() error {
|
|||
}
|
||||
_, _, err = a.apiClient.Metrics.Add(context.Background(), metrics)
|
||||
if err != nil {
|
||||
log.Errorf("capi metrics: failed: %s", err.Error())
|
||||
log.Errorf("capi metrics: failed: %s", err)
|
||||
} else {
|
||||
log.Infof("capi metrics: metrics sent successfully")
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ type TLSCfg struct {
|
|||
func (c *Config) LoadAPIServer() error {
|
||||
if c.API.Server != nil && !c.DisableAPI {
|
||||
if err := c.LoadCommon(); err != nil {
|
||||
return fmt.Errorf("loading common configuration: %s", err.Error())
|
||||
return fmt.Errorf("loading common configuration: %s", err)
|
||||
}
|
||||
c.API.Server.LogDir = c.Common.LogDir
|
||||
c.API.Server.LogMedia = c.Common.LogMedia
|
||||
|
|
|
@ -111,7 +111,7 @@ func (c *Config) LoadCrowdsec() error {
|
|||
}
|
||||
|
||||
if err := c.LoadAPIClient(); err != nil {
|
||||
return fmt.Errorf("loading api client: %s", err.Error())
|
||||
return fmt.Errorf("loading api client: %s", err)
|
||||
}
|
||||
if err := c.LoadHub(); err != nil {
|
||||
return errors.Wrap(err, "while loading hub")
|
||||
|
|
|
@ -311,7 +311,7 @@ func (pb *PluginBroker) pushNotificationsToPlugin(pluginName string, alerts []*m
|
|||
if err == nil {
|
||||
return err
|
||||
}
|
||||
log.WithField("plugin", pluginName).Errorf("%s error, retry num %d", err.Error(), i)
|
||||
log.WithField("plugin", pluginName).Errorf("%s error, retry num %d", err, i)
|
||||
time.Sleep(backoffDuration)
|
||||
backoffDuration *= 2
|
||||
}
|
||||
|
@ -334,7 +334,7 @@ func ParsePluginConfigFile(path string) ([]PluginConfig, error) {
|
|||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
return []PluginConfig{}, fmt.Errorf("while decoding %s got error %s", path, err.Error())
|
||||
return []PluginConfig{}, fmt.Errorf("while decoding %s got error %s", path, err)
|
||||
}
|
||||
parsedConfigs = append(parsedConfigs, pc)
|
||||
}
|
||||
|
|
|
@ -515,7 +515,7 @@ func (t *HubTestItem) Run() error {
|
|||
|
||||
logFileStat, err := os.Stat(logFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to stat log file '%s': %s", logFile, err.Error())
|
||||
return fmt.Errorf("unable to stat log file '%s': %s", logFile, err)
|
||||
}
|
||||
if logFileStat.Size() == 0 {
|
||||
return fmt.Errorf("Log file '%s' is empty, please fill it with log", logFile)
|
||||
|
@ -569,7 +569,7 @@ func (t *HubTestItem) Run() error {
|
|||
if assertFileStat.Size() == 0 {
|
||||
assertData, err := t.ParserAssert.AutoGenFromFile(t.ParserResultFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't generate assertion: %s", err.Error())
|
||||
return fmt.Errorf("couldn't generate assertion: %s", err)
|
||||
}
|
||||
t.ParserAssert.AutoGenAssertData = assertData
|
||||
t.ParserAssert.AutoGenAssert = true
|
||||
|
@ -605,7 +605,7 @@ func (t *HubTestItem) Run() error {
|
|||
if assertFileStat.Size() == 0 {
|
||||
assertData, err := t.ScenarioAssert.AutoGenFromFile(t.ScenarioResultFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't generate assertion: %s", err.Error())
|
||||
return fmt.Errorf("couldn't generate assertion: %s", err)
|
||||
}
|
||||
t.ScenarioAssert.AutoGenAssertData = assertData
|
||||
t.ScenarioAssert.AutoGenAssert = true
|
||||
|
|
|
@ -131,7 +131,7 @@ func (p *ParserAssert) AssertFile(testFile string) error {
|
|||
if p.NbAssert == 0 {
|
||||
assertData, err := p.AutoGenFromFile(testFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't generate assertion: %s", err.Error())
|
||||
return fmt.Errorf("couldn't generate assertion: %s", err)
|
||||
}
|
||||
p.AutoGenAssertData = assertData
|
||||
p.AutoGenAssert = true
|
||||
|
|
|
@ -126,7 +126,7 @@ func (s *ScenarioAssert) AssertFile(testFile string) error {
|
|||
if s.NbAssert == 0 {
|
||||
assertData, err := s.AutoGenFromFile(testFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't generate assertion: %s", err.Error())
|
||||
return fmt.Errorf("couldn't generate assertion: %s", err)
|
||||
}
|
||||
s.AutoGenAssertData = assertData
|
||||
s.AutoGenAssert = true
|
||||
|
|
|
@ -117,14 +117,14 @@ func getSHA256(filepath string) (string, error) {
|
|||
/* Digest of file */
|
||||
f, err := os.Open(filepath)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to open '%s' : %s", filepath, err.Error())
|
||||
return "", fmt.Errorf("unable to open '%s' : %s", filepath, err)
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
h := sha256.New()
|
||||
if _, err := io.Copy(h, f); err != nil {
|
||||
return "", fmt.Errorf("unable to calculate sha256 of '%s': %s", filepath, err.Error())
|
||||
return "", fmt.Errorf("unable to calculate sha256 of '%s': %s", filepath, err)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%x", h.Sum(nil)), nil
|
||||
|
|
|
@ -514,7 +514,7 @@ func (c *Client) CreateAlertBulk(machineId string, alertList []*models.Alert) ([
|
|||
for _, d2 := range decisionsChunk {
|
||||
_, err := c.Ent.Alert.Update().Where(alert.IDEQ(a.ID)).AddDecisions(d2...).Save(c.CTX)
|
||||
if err != nil {
|
||||
return []string{}, fmt.Errorf("error while updating decisions: %s", err.Error())
|
||||
return []string{}, fmt.Errorf("error while updating decisions: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -540,7 +540,7 @@ func (c *Client) CreateAlertBulk(machineId string, alertList []*models.Alert) ([
|
|||
for _, d2 := range decisionsChunk {
|
||||
_, err := c.Ent.Alert.Update().Where(alert.IDEQ(a.ID)).AddDecisions(d2...).Save(c.CTX)
|
||||
if err != nil {
|
||||
return []string{}, fmt.Errorf("error while updating decisions: %s", err.Error())
|
||||
return []string{}, fmt.Errorf("error while updating decisions: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,17 +106,17 @@ func TestVisitor(t *testing.T) {
|
|||
for _, test := range tests {
|
||||
compiledFilter, err := expr.Compile(test.filter, expr.Env(GetExprEnv(test.env)))
|
||||
if err != nil && test.err == nil {
|
||||
log.Fatalf("compile: %s", err.Error())
|
||||
log.Fatalf("compile: %s", err)
|
||||
}
|
||||
debugFilter, err := NewDebugger(test.filter, expr.Env(GetExprEnv(test.env)))
|
||||
if err != nil && test.err == nil {
|
||||
log.Fatalf("debug: %s", err.Error())
|
||||
log.Fatalf("debug: %s", err)
|
||||
}
|
||||
|
||||
if compiledFilter != nil {
|
||||
result, err := expr.Run(compiledFilter, GetExprEnv(test.env))
|
||||
if err != nil && test.err == nil {
|
||||
log.Fatalf("run : %s", err.Error())
|
||||
log.Fatalf("run : %s", err)
|
||||
}
|
||||
if isOk := assert.Equal(t, test.result, result); !isOk {
|
||||
t.Fatalf("test '%s' : NOK", test.filter)
|
||||
|
|
|
@ -339,7 +339,7 @@ func LoadBucket(bucketFactory *BucketFactory, tomb *tomb.Tomb) error {
|
|||
}
|
||||
err = exprhelpers.FileInit(bucketFactory.DataDir, data.DestPath, data.Type)
|
||||
if err != nil {
|
||||
bucketFactory.logger.Errorf("unable to init data for file '%s': %s", data.DestPath, err.Error())
|
||||
bucketFactory.logger.Errorf("unable to init data for file '%s': %s", data.DestPath, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,9 +102,9 @@ func LoadStages(stageFiles []Stagefile, pctx *UnixParserCtx, ectx EnricherCtx) (
|
|||
err = node.compile(pctx, ectx)
|
||||
if err != nil {
|
||||
if node.Name != "" {
|
||||
return nil, fmt.Errorf("failed to compile node '%s' in '%s' : %s", node.Name, stageFile.Filename, err.Error())
|
||||
return nil, fmt.Errorf("failed to compile node '%s' in '%s' : %s", node.Name, stageFile.Filename, err)
|
||||
}
|
||||
return nil, fmt.Errorf("failed to compile node in '%s' : %s", stageFile.Filename, err.Error())
|
||||
return nil, fmt.Errorf("failed to compile node in '%s' : %s", stageFile.Filename, err)
|
||||
}
|
||||
/* if the stage is empty, the node is empty, it's a trailing entry in users yaml file */
|
||||
if node.Stage == "" {
|
||||
|
|
|
@ -12,7 +12,7 @@ func TestIP2Int(t *testing.T) {
|
|||
tEmpty := net.IP{}
|
||||
_, _, _, err := IP2Ints(tEmpty)
|
||||
if !strings.Contains(err.Error(), "unexpected len 0 for <nil>") {
|
||||
t.Fatalf("unexpected: %s", err.Error())
|
||||
t.Fatalf("unexpected: %s", err)
|
||||
}
|
||||
}
|
||||
func TestRange2Int(t *testing.T) {
|
||||
|
@ -20,7 +20,7 @@ func TestRange2Int(t *testing.T) {
|
|||
//empty item
|
||||
_, _, _, _, _, err := Range2Ints(tEmpty)
|
||||
if !strings.Contains(err.Error(), "converting first ip in range") {
|
||||
t.Fatalf("unexpected: %s", err.Error())
|
||||
t.Fatalf("unexpected: %s", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ func (s *HTTPPlugin) Notify(ctx context.Context, notification *protobufs.Notific
|
|||
|
||||
respData, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read response body got error %s", string(err.Error()))
|
||||
return nil, fmt.Errorf("failed to read response body got error %s", err)
|
||||
}
|
||||
|
||||
logger.Debug(fmt.Sprintf("got response %s", string(respData)))
|
||||
|
|
|
@ -73,13 +73,13 @@ func (s *Splunk) Notify(ctx context.Context, notification *protobufs.Notificatio
|
|||
if resp.StatusCode != 200 {
|
||||
content, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return &protobufs.Empty{}, fmt.Errorf("got non 200 response and failed to read error %s", string(err.Error()))
|
||||
return &protobufs.Empty{}, fmt.Errorf("got non 200 response and failed to read error %s", err)
|
||||
}
|
||||
return &protobufs.Empty{}, fmt.Errorf("got non 200 response %s", string(content))
|
||||
}
|
||||
respData, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return &protobufs.Empty{}, fmt.Errorf("failed to read response body got error %s", string(err.Error()))
|
||||
return &protobufs.Empty{}, fmt.Errorf("failed to read response body got error %s", err)
|
||||
}
|
||||
logger.Debug(fmt.Sprintf("got response %s", string(respData)))
|
||||
return &protobufs.Empty{}, nil
|
||||
|
|
Loading…
Reference in a new issue