Clean code style - amtool errors (#1099)

This commit is contained in:
Jose Donizetti 2017-11-12 14:43:48 -02:00 committed by stuart nelson
parent 7168749a9f
commit 7151cd4bfc
8 changed files with 13 additions and 13 deletions

View File

@ -103,7 +103,7 @@ func fetchAlerts(filter string) ([]*dispatch.APIAlert, error) {
err = json.NewDecoder(res.Body).Decode(&alertResponse)
if err != nil {
return []*dispatch.APIAlert{}, fmt.Errorf("Unable to decode json response: %s", err)
return []*dispatch.APIAlert{}, fmt.Errorf("unable to decode json response: %s", err)
}
if alertResponse.Status != "success" {
@ -168,7 +168,7 @@ func queryAlerts(cmd *cobra.Command, args []string) error {
formatter, found := format.Formatters[viper.GetString("output")]
if !found {
return errors.New("Unknown output formatter")
return errors.New("unknown output formatter")
}
return formatter.FormatAlerts(displayAlerts)
}

View File

@ -59,7 +59,7 @@ func CheckConfig(args []string) error {
fmt.Printf("\n")
}
if failed > 0 {
return fmt.Errorf("Failed to validate %d file(s).", failed)
return fmt.Errorf("failed to validate %d file(s)", failed)
}
return nil
}

View File

@ -7,11 +7,11 @@ import (
func TestCheckConfig(t *testing.T) {
err := CheckConfig([]string{"testdata/conf.good.yml"})
if err != nil {
t.Fatalf("Checking valid config file failed with: %v", err)
t.Fatalf("checking valid config file failed with: %v", err)
}
err = CheckConfig([]string{"testdata/conf.bad.yml"})
if err == nil {
t.Fatalf("Failed to detect invalid file.")
t.Fatalf("failed to detect invalid file.")
}
}

View File

@ -95,7 +95,7 @@ func queryConfig(cmd *cobra.Command, args []string) error {
formatter, found := format.Formatters[viper.GetString("output")]
if !found {
return errors.New("Unknown output formatter")
return errors.New("unknown output formatter")
}
c := format.Config(config)

View File

@ -19,7 +19,7 @@ import (
type addResponse struct {
Status string `json:"status"`
Data struct {
Data struct {
SilenceID string `json:"silenceId"`
} `json:"data,omitempty"`
ErrorType string `json:"errorType,omitempty"`
@ -86,7 +86,7 @@ func add(cmd *cobra.Command, args []string) error {
}
if len(matchers) < 1 {
return fmt.Errorf("No matchers specified")
return fmt.Errorf("no matchers specified")
}
expireOn, err := addFlags.GetString("expire-on")
@ -118,7 +118,7 @@ func add(cmd *cobra.Command, args []string) error {
commentRequired := viper.GetBool("comment_required")
if commentRequired && comment == "" {
return errors.New("Comment required by config")
return errors.New("comment required by config")
}
typeMatchers, err := TypeMatchers(matchers)
@ -155,7 +155,7 @@ func add(cmd *cobra.Command, args []string) error {
response := addResponse{}
err = json.NewDecoder(res.Body).Decode(&response)
if err != nil {
return fmt.Errorf("Unable to parse silence json response from %s", u.String())
return fmt.Errorf("unable to parse silence json response from %s", u.String())
}
if response.Status == "error" {

View File

@ -24,7 +24,7 @@ func expire(cmd *cobra.Command, args []string) error {
basePath := path.Join(u.Path, "/api/v1/silence")
if len(args) < 1 {
return errors.New("No silence IDs specified")
return errors.New("no silence IDs specified")
}
for _, arg := range args {

View File

@ -127,7 +127,7 @@ func query(cmd *cobra.Command, args []string) error {
} else {
formatter, found := format.Formatters[viper.GetString("output")]
if !found {
return errors.New("Unknown output formatter")
return errors.New("unknown output formatter")
}
formatter.FormatSilences(displaySilences)
}

View File

@ -33,7 +33,7 @@ func (s ByAlphabetical) Less(i, j int) bool {
func GetAlertmanagerURL() (*url.URL, error) {
u, err := url.ParseRequestURI(viper.GetString("alertmanager.url"))
if err != nil {
return nil, errors.New("Invalid alertmanager url")
return nil, errors.New("invalid alertmanager url")
}
return u, nil
}