Chore: Remove Wrap (#50048)

* Chore: Remove Wrap and Wrapf

* Fix: Add error check
This commit is contained in:
Kat Yang
2022-06-03 09:24:24 +02:00
committed by GitHub
parent 53cb94a2ad
commit 3c3039f5b3
34 changed files with 104 additions and 117 deletions
@@ -22,7 +22,6 @@ import (
"github.com/grafana/grafana/pkg/tsdb/azuremonitor/azlog"
"github.com/grafana/grafana/pkg/tsdb/azuremonitor/macros"
"github.com/grafana/grafana/pkg/tsdb/azuremonitor/types"
"github.com/grafana/grafana/pkg/util/errutil"
)
// AzureLogAnalyticsDatasource calls the Azure Log Analytics API's
@@ -227,7 +226,7 @@ func (e *AzureLogAnalyticsDatasource) createRequest(ctx context.Context, dsInfo
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
azlog.Debug("Failed to create request", "error", err)
return nil, errutil.Wrap("failed to create request", err)
return nil, fmt.Errorf("%v: %w", "failed to create request", err)
}
req.URL.Path = "/"
req.Header.Set("Content-Type", "application/json")
@@ -23,7 +23,6 @@ import (
"github.com/grafana/grafana/pkg/tsdb/azuremonitor/resourcegraph"
azTime "github.com/grafana/grafana/pkg/tsdb/azuremonitor/time"
"github.com/grafana/grafana/pkg/tsdb/azuremonitor/types"
"github.com/grafana/grafana/pkg/util/errutil"
)
// AzureMonitorDatasource calls the Azure Monitor API - one of the four API's supported
@@ -231,7 +230,7 @@ func (e *AzureMonitorDatasource) createRequest(ctx context.Context, dsInfo types
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
azlog.Debug("Failed to create request", "error", err)
return nil, errutil.Wrap("Failed to create request", err)
return nil, fmt.Errorf("%v: %w", "Failed to create request", err)
}
req.Header.Set("Content-Type", "application/json")
@@ -23,7 +23,6 @@ import (
"github.com/grafana/grafana/pkg/tsdb/azuremonitor/loganalytics"
"github.com/grafana/grafana/pkg/tsdb/azuremonitor/macros"
"github.com/grafana/grafana/pkg/tsdb/azuremonitor/types"
"github.com/grafana/grafana/pkg/util/errutil"
)
// AzureResourceGraphResponse is the json response object from the Azure Resource Graph Analytics API.
@@ -229,7 +228,7 @@ func (e *AzureResourceGraphDatasource) createRequest(ctx context.Context, dsInfo
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewBuffer(reqBody))
if err != nil {
azlog.Debug("Failed to create request", "error", err)
return nil, errutil.Wrap("failed to create request", err)
return nil, fmt.Errorf("%v: %w", "failed to create request", err)
}
req.URL.Path = "/"
req.Header.Set("Content-Type", "application/json")
+4 -4
View File
@@ -2,6 +2,7 @@ package cloudwatch
import (
"errors"
"fmt"
"time"
"github.com/aws/aws-sdk-go/aws"
@@ -9,7 +10,6 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/util/errutil"
)
type annotationEvent struct {
@@ -49,7 +49,7 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(pluginCtx backend.PluginCont
}
resp, err := cli.DescribeAlarms(params)
if err != nil {
return nil, errutil.Wrap("failed to call cloudwatch:DescribeAlarms", err)
return nil, fmt.Errorf("%v: %w", "failed to call cloudwatch:DescribeAlarms", err)
}
alarmNames = filterAlarms(resp, namespace, metricName, dimensions, statistic, period)
} else {
@@ -79,7 +79,7 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(pluginCtx backend.PluginCont
}
resp, err := cli.DescribeAlarmsForMetric(params)
if err != nil {
return nil, errutil.Wrap("failed to call cloudwatch:DescribeAlarmsForMetric", err)
return nil, fmt.Errorf("%v: %w", "failed to call cloudwatch:DescribeAlarmsForMetric", err)
}
for _, alarm := range resp.MetricAlarms {
alarmNames = append(alarmNames, alarm.AlarmName)
@@ -96,7 +96,7 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(pluginCtx backend.PluginCont
}
resp, err := cli.DescribeAlarmHistory(params)
if err != nil {
return nil, errutil.Wrap("failed to call cloudwatch:DescribeAlarmHistory", err)
return nil, fmt.Errorf("%v: %w", "failed to call cloudwatch:DescribeAlarmHistory", err)
}
for _, history := range resp.AlarmHistoryItems {
annotations = append(annotations, &annotationEvent{
+3 -4
View File
@@ -18,7 +18,6 @@ import (
"github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/util/errutil"
)
type suggestData struct {
@@ -140,7 +139,7 @@ func (e *cloudWatchExecutor) handleGetMetrics(pluginCtx backend.PluginContext, p
} else {
var err error
if namespaceMetrics, err = e.getMetricsForCustomMetrics(region, namespace, pluginCtx); err != nil {
return nil, errutil.Wrap("unable to call AWS API", err)
return nil, fmt.Errorf("%v: %w", "unable to call AWS API", err)
}
}
sort.Strings(namespaceMetrics)
@@ -222,7 +221,7 @@ func (e *cloudWatchExecutor) handleGetDimensionKeys(pluginCtx backend.PluginCont
region, input)
if err != nil {
return nil, errutil.Wrap("unable to call AWS API", err)
return nil, fmt.Errorf("%v: %w", "unable to call AWS API", err)
}
dupCheck := make(map[string]bool)
@@ -250,7 +249,7 @@ func (e *cloudWatchExecutor) handleGetDimensionKeys(pluginCtx backend.PluginCont
} else {
var err error
if dimensionValues, err = e.getDimensionsForCustomMetrics(region, namespace, pluginCtx); err != nil {
return nil, errutil.Wrap("unable to call AWS API", err)
return nil, fmt.Errorf("%v: %w", "unable to call AWS API", err)
}
}
sort.Strings(dimensionValues)
+2 -3
View File
@@ -18,7 +18,6 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/data/sqlutil"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/tsdb/intervalv2"
"github.com/grafana/grafana/pkg/util/errutil"
"xorm.io/core"
"xorm.io/xorm"
)
@@ -823,13 +822,13 @@ func convertNullableFloat32ToEpochMS(origin *data.Field, newField *data.Field) {
func convertSQLTimeColumnsToEpochMS(frame *data.Frame, qm *dataQueryModel) error {
if qm.timeIndex != -1 {
if err := convertSQLTimeColumnToEpochMS(frame, qm.timeIndex); err != nil {
return errutil.Wrap("failed to convert time column", err)
return fmt.Errorf("%v: %w", "failed to convert time column", err)
}
}
if qm.timeEndIndex != -1 {
if err := convertSQLTimeColumnToEpochMS(frame, qm.timeEndIndex); err != nil {
return errutil.Wrap("failed to convert timeend column", err)
return fmt.Errorf("%v: %w", "failed to convert timeend column", err)
}
}