mirror of
https://github.com/grafana/grafana.git
synced 2025-01-15 19:22:34 -06:00
Chore: Change fmt.Errorf to errors.New when there is no formatting required (#58600)
Signed-off-by: Sasha Melentyev <sasha@melentyev.io>
This commit is contained in:
parent
fb98a97efa
commit
f0adc69ada
@ -490,11 +490,11 @@ func (hs *HTTPServer) getListener() (net.Listener, error) {
|
||||
|
||||
func (hs *HTTPServer) configureHttps() error {
|
||||
if hs.Cfg.CertFile == "" {
|
||||
return fmt.Errorf("cert_file cannot be empty when using HTTPS")
|
||||
return errors.New("cert_file cannot be empty when using HTTPS")
|
||||
}
|
||||
|
||||
if hs.Cfg.KeyFile == "" {
|
||||
return fmt.Errorf("cert_key cannot be empty when using HTTPS")
|
||||
return errors.New("cert_key cannot be empty when using HTTPS")
|
||||
}
|
||||
|
||||
if _, err := os.Stat(hs.Cfg.CertFile); os.IsNotExist(err) {
|
||||
@ -530,19 +530,19 @@ func (hs *HTTPServer) configureHttps() error {
|
||||
|
||||
func (hs *HTTPServer) configureHttp2() error {
|
||||
if hs.Cfg.CertFile == "" {
|
||||
return fmt.Errorf("cert_file cannot be empty when using HTTP2")
|
||||
return errors.New("cert_file cannot be empty when using HTTP2")
|
||||
}
|
||||
|
||||
if hs.Cfg.KeyFile == "" {
|
||||
return fmt.Errorf("cert_key cannot be empty when using HTTP2")
|
||||
return errors.New("cert_key cannot be empty when using HTTP2")
|
||||
}
|
||||
|
||||
if _, err := os.Stat(hs.Cfg.CertFile); os.IsNotExist(err) {
|
||||
return fmt.Errorf(`cannot find SSL cert_file at %q`, hs.Cfg.CertFile)
|
||||
return fmt.Errorf("cannot find SSL cert_file at %q", hs.Cfg.CertFile)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(hs.Cfg.KeyFile); os.IsNotExist(err) {
|
||||
return fmt.Errorf(`cannot find SSL key_file at %q`, hs.Cfg.KeyFile)
|
||||
return fmt.Errorf("cannot find SSL key_file at %q", hs.Cfg.KeyFile)
|
||||
}
|
||||
|
||||
tlsCfg := &tls.Config{
|
||||
@ -664,9 +664,8 @@ func (hs *HTTPServer) healthzHandler(ctx *web.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Resp.WriteHeader(200)
|
||||
_, err := ctx.Resp.Write([]byte("Ok"))
|
||||
if err != nil {
|
||||
ctx.Resp.WriteHeader(http.StatusOK)
|
||||
if _, err := ctx.Resp.Write([]byte("Ok")); err != nil {
|
||||
hs.log.Error("could not write to response", "err", err)
|
||||
}
|
||||
}
|
||||
@ -690,10 +689,10 @@ func (hs *HTTPServer) apiHealthHandler(ctx *web.Context) {
|
||||
if !hs.databaseHealthy(ctx.Req.Context()) {
|
||||
data.Set("database", "failing")
|
||||
ctx.Resp.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
ctx.Resp.WriteHeader(503)
|
||||
ctx.Resp.WriteHeader(http.StatusServiceUnavailable)
|
||||
} else {
|
||||
ctx.Resp.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
ctx.Resp.WriteHeader(200)
|
||||
ctx.Resp.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
dataBytes, err := data.EncodePretty()
|
||||
|
@ -55,7 +55,7 @@ func TestAPIEndpoint_Metrics_QueryMetricsV2(t *testing.T) {
|
||||
QueryDataHandlerFunc: func(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||
resp := backend.Responses{
|
||||
"A": backend.DataResponse{
|
||||
Error: fmt.Errorf("query failed"),
|
||||
Error: errors.New("query failed"),
|
||||
},
|
||||
}
|
||||
return &backend.QueryDataResponse{Responses: resp}, nil
|
||||
@ -103,7 +103,7 @@ func TestAPIEndpoint_Metrics_PluginDecryptionFailure(t *testing.T) {
|
||||
QueryDataHandlerFunc: func(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||
resp := backend.Responses{
|
||||
"A": backend.DataResponse{
|
||||
Error: fmt.Errorf("query failed"),
|
||||
Error: errors.New("query failed"),
|
||||
},
|
||||
}
|
||||
return &backend.QueryDataResponse{Responses: resp}, nil
|
||||
|
@ -2,7 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
@ -85,23 +85,21 @@ func (hs *HTTPServer) LoadPlaylistDashboards(ctx context.Context, orgID int64, s
|
||||
dashboardTagOrder := make(map[string]int)
|
||||
|
||||
for i, item := range playlistItems {
|
||||
if item.Type == "dashboard_by_id" {
|
||||
switch item.Type {
|
||||
case "dashboard_by_id":
|
||||
dashboardID, _ := strconv.ParseInt(item.Value, 10, 64)
|
||||
dashboardByIDs = append(dashboardByIDs, dashboardID)
|
||||
dashboardIDOrder[dashboardID] = i
|
||||
}
|
||||
|
||||
if item.Type == "dashboard_by_tag" {
|
||||
case "dashboard_by_tag":
|
||||
dashboardByTag = append(dashboardByTag, item.Value)
|
||||
dashboardTagOrder[item.Value] = i
|
||||
}
|
||||
|
||||
if item.Type == "dashboard_by_uid" {
|
||||
return nil, fmt.Errorf("dashboard_by_uid not supported by this deprecated API")
|
||||
case "dashboard_by_uid":
|
||||
return nil, errors.New("dashboard_by_uid not supported by this deprecated API")
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
var k, _ = hs.populateDashboardsByID(ctx, dashboardByIDs, dashboardIDOrder)
|
||||
k, _ := hs.populateDashboardsByID(ctx, dashboardByIDs, dashboardIDOrder)
|
||||
result = append(result, k...)
|
||||
result = append(result, hs.populateDashboardsByTag(ctx, orgID, signedInUser, dashboardByTag, dashboardTagOrder)...)
|
||||
|
||||
|
@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@ -35,7 +36,7 @@ func TestGetPluginDashboards(t *testing.T) {
|
||||
},
|
||||
},
|
||||
unexpectedErrors: map[string]error{
|
||||
"boom": fmt.Errorf("BOOM"),
|
||||
"boom": errors.New("BOOM"),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@ -889,7 +890,7 @@ func TestNewDataSourceProxy_MSSQL(t *testing.T) {
|
||||
description: "Invalid ODBC URL",
|
||||
url: `localhost\instance::1433`,
|
||||
err: datasource.URLValidationError{
|
||||
Err: fmt.Errorf(`unrecognized MSSQL URL format: "localhost\\instance::1433"`),
|
||||
Err: errors.New(`unrecognized MSSQL URL format: "localhost\\instance::1433"`),
|
||||
URL: `localhost\instance::1433`,
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user