From c980f3750931515387ea4147baa1ea15c4092dff Mon Sep 17 00:00:00 2001 From: Kyle Brandt Date: Wed, 15 Jul 2020 15:55:10 -0400 Subject: [PATCH] Azure: Insights Analytics, fix possible panics and return error body (#26361) missing return statements can result in panic --- .../azuremonitor/insights-analytics-datasource.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/tsdb/azuremonitor/insights-analytics-datasource.go b/pkg/tsdb/azuremonitor/insights-analytics-datasource.go index e41f5a5c788..84c6a325863 100644 --- a/pkg/tsdb/azuremonitor/insights-analytics-datasource.go +++ b/pkg/tsdb/azuremonitor/insights-analytics-datasource.go @@ -104,7 +104,7 @@ func (e *InsightsAnalyticsDatasource) executeQuery(ctx context.Context, query *I req, err := e.createRequest(ctx, e.dsInfo) if err != nil { - queryResultError(err) + return queryResultError(err) } req.URL.Path = path.Join(req.URL.Path, "query") req.URL.RawQuery = query.Params.Encode() @@ -128,30 +128,30 @@ func (e *InsightsAnalyticsDatasource) executeQuery(ctx context.Context, query *I azlog.Debug("ApplicationInsights", "Request URL", req.URL.String()) res, err := ctxhttp.Do(ctx, e.httpClient, req) if err != nil { - queryResultError(err) + return queryResultError(err) } body, err := ioutil.ReadAll(res.Body) defer res.Body.Close() if err != nil { - queryResultError(err) + return queryResultError(err) } if res.StatusCode/100 != 2 { azlog.Debug("Request failed", "status", res.Status, "body", string(body)) - queryResultError(fmt.Errorf("Request failed status: %v", res.Status)) + return queryResultError(fmt.Errorf("Request failed status: %v %w", res.Status, fmt.Errorf(string(body)))) } var logResponse AzureLogAnalyticsResponse d := json.NewDecoder(bytes.NewReader(body)) d.UseNumber() err = d.Decode(&logResponse) if err != nil { - queryResultError(err) + return queryResultError(err) } t, err := logResponse.GetPrimaryResultTable() if err != nil { - queryResultError(err) + return queryResultError(err) } frame, err := LogTableToFrame(t)