Skip to content

Commit 297fea3

Browse files
fix undefined execution order in return statements (#1260)
Signed-off-by: Piotr Lewandowski <[email protected]>
1 parent 0f060a0 commit 297fea3

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

api/prometheus/v1/api.go

+34-17
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,8 @@ func (h *httpAPI) Alerts(ctx context.Context) (AlertsResult, error) {
892892
}
893893

894894
var res AlertsResult
895-
return res, json.Unmarshal(body, &res)
895+
err = json.Unmarshal(body, &res)
896+
return res, err
896897
}
897898

898899
func (h *httpAPI) AlertManagers(ctx context.Context) (AlertManagersResult, error) {
@@ -909,7 +910,8 @@ func (h *httpAPI) AlertManagers(ctx context.Context) (AlertManagersResult, error
909910
}
910911

911912
var res AlertManagersResult
912-
return res, json.Unmarshal(body, &res)
913+
err = json.Unmarshal(body, &res)
914+
return res, err
913915
}
914916

915917
func (h *httpAPI) CleanTombstones(ctx context.Context) error {
@@ -938,7 +940,8 @@ func (h *httpAPI) Config(ctx context.Context) (ConfigResult, error) {
938940
}
939941

940942
var res ConfigResult
941-
return res, json.Unmarshal(body, &res)
943+
err = json.Unmarshal(body, &res)
944+
return res, err
942945
}
943946

944947
func (h *httpAPI) DeleteSeries(ctx context.Context, matches []string, startTime, endTime time.Time) error {
@@ -981,7 +984,8 @@ func (h *httpAPI) Flags(ctx context.Context) (FlagsResult, error) {
981984
}
982985

983986
var res FlagsResult
984-
return res, json.Unmarshal(body, &res)
987+
err = json.Unmarshal(body, &res)
988+
return res, err
985989
}
986990

987991
func (h *httpAPI) Buildinfo(ctx context.Context) (BuildinfoResult, error) {
@@ -998,7 +1002,8 @@ func (h *httpAPI) Buildinfo(ctx context.Context) (BuildinfoResult, error) {
9981002
}
9991003

10001004
var res BuildinfoResult
1001-
return res, json.Unmarshal(body, &res)
1005+
err = json.Unmarshal(body, &res)
1006+
return res, err
10021007
}
10031008

10041009
func (h *httpAPI) Runtimeinfo(ctx context.Context) (RuntimeinfoResult, error) {
@@ -1015,7 +1020,8 @@ func (h *httpAPI) Runtimeinfo(ctx context.Context) (RuntimeinfoResult, error) {
10151020
}
10161021

10171022
var res RuntimeinfoResult
1018-
return res, json.Unmarshal(body, &res)
1023+
err = json.Unmarshal(body, &res)
1024+
return res, err
10191025
}
10201026

10211027
func (h *httpAPI) LabelNames(ctx context.Context, matches []string, startTime, endTime time.Time) ([]string, Warnings, error) {
@@ -1036,7 +1042,8 @@ func (h *httpAPI) LabelNames(ctx context.Context, matches []string, startTime, e
10361042
return nil, w, err
10371043
}
10381044
var labelNames []string
1039-
return labelNames, w, json.Unmarshal(body, &labelNames)
1045+
err = json.Unmarshal(body, &labelNames)
1046+
return labelNames, w, err
10401047
}
10411048

10421049
func (h *httpAPI) LabelValues(ctx context.Context, label string, matches []string, startTime, endTime time.Time) (model.LabelValues, Warnings, error) {
@@ -1063,7 +1070,8 @@ func (h *httpAPI) LabelValues(ctx context.Context, label string, matches []strin
10631070
return nil, w, err
10641071
}
10651072
var labelValues model.LabelValues
1066-
return labelValues, w, json.Unmarshal(body, &labelValues)
1073+
err = json.Unmarshal(body, &labelValues)
1074+
return labelValues, w, err
10671075
}
10681076

10691077
type apiOptions struct {
@@ -1158,7 +1166,8 @@ func (h *httpAPI) Series(ctx context.Context, matches []string, startTime, endTi
11581166
}
11591167

11601168
var mset []model.LabelSet
1161-
return mset, warnings, json.Unmarshal(body, &mset)
1169+
err = json.Unmarshal(body, &mset)
1170+
return mset, warnings, err
11621171
}
11631172

11641173
func (h *httpAPI) Snapshot(ctx context.Context, skipHead bool) (SnapshotResult, error) {
@@ -1180,7 +1189,8 @@ func (h *httpAPI) Snapshot(ctx context.Context, skipHead bool) (SnapshotResult,
11801189
}
11811190

11821191
var res SnapshotResult
1183-
return res, json.Unmarshal(body, &res)
1192+
err = json.Unmarshal(body, &res)
1193+
return res, err
11841194
}
11851195

11861196
func (h *httpAPI) Rules(ctx context.Context) (RulesResult, error) {
@@ -1197,7 +1207,8 @@ func (h *httpAPI) Rules(ctx context.Context) (RulesResult, error) {
11971207
}
11981208

11991209
var res RulesResult
1200-
return res, json.Unmarshal(body, &res)
1210+
err = json.Unmarshal(body, &res)
1211+
return res, err
12011212
}
12021213

12031214
func (h *httpAPI) Targets(ctx context.Context) (TargetsResult, error) {
@@ -1214,7 +1225,8 @@ func (h *httpAPI) Targets(ctx context.Context) (TargetsResult, error) {
12141225
}
12151226

12161227
var res TargetsResult
1217-
return res, json.Unmarshal(body, &res)
1228+
err = json.Unmarshal(body, &res)
1229+
return res, err
12181230
}
12191231

12201232
func (h *httpAPI) TargetsMetadata(ctx context.Context, matchTarget, metric, limit string) ([]MetricMetadata, error) {
@@ -1238,7 +1250,8 @@ func (h *httpAPI) TargetsMetadata(ctx context.Context, matchTarget, metric, limi
12381250
}
12391251

12401252
var res []MetricMetadata
1241-
return res, json.Unmarshal(body, &res)
1253+
err = json.Unmarshal(body, &res)
1254+
return res, err
12421255
}
12431256

12441257
func (h *httpAPI) Metadata(ctx context.Context, metric, limit string) (map[string][]Metadata, error) {
@@ -1261,7 +1274,8 @@ func (h *httpAPI) Metadata(ctx context.Context, metric, limit string) (map[strin
12611274
}
12621275

12631276
var res map[string][]Metadata
1264-
return res, json.Unmarshal(body, &res)
1277+
err = json.Unmarshal(body, &res)
1278+
return res, err
12651279
}
12661280

12671281
func (h *httpAPI) TSDB(ctx context.Context) (TSDBResult, error) {
@@ -1278,7 +1292,8 @@ func (h *httpAPI) TSDB(ctx context.Context) (TSDBResult, error) {
12781292
}
12791293

12801294
var res TSDBResult
1281-
return res, json.Unmarshal(body, &res)
1295+
err = json.Unmarshal(body, &res)
1296+
return res, err
12821297
}
12831298

12841299
func (h *httpAPI) WalReplay(ctx context.Context) (WalReplayStatus, error) {
@@ -1295,7 +1310,8 @@ func (h *httpAPI) WalReplay(ctx context.Context) (WalReplayStatus, error) {
12951310
}
12961311

12971312
var res WalReplayStatus
1298-
return res, json.Unmarshal(body, &res)
1313+
err = json.Unmarshal(body, &res)
1314+
return res, err
12991315
}
13001316

13011317
func (h *httpAPI) QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) ([]ExemplarQueryResult, error) {
@@ -1316,7 +1332,8 @@ func (h *httpAPI) QueryExemplars(ctx context.Context, query string, startTime, e
13161332
}
13171333

13181334
var res []ExemplarQueryResult
1319-
return res, json.Unmarshal(body, &res)
1335+
err = json.Unmarshal(body, &res)
1336+
return res, err
13201337
}
13211338

13221339
// Warnings is an array of non critical errors

0 commit comments

Comments
 (0)