Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined execution order in return statements #1260

Merged
merged 1 commit into from May 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 34 additions & 17 deletions api/prometheus/v1/api.go
Expand Up @@ -892,7 +892,8 @@ func (h *httpAPI) Alerts(ctx context.Context) (AlertsResult, error) {
}

var res AlertsResult
return res, json.Unmarshal(body, &res)
err = json.Unmarshal(body, &res)
return res, err
}

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

var res AlertManagersResult
return res, json.Unmarshal(body, &res)
err = json.Unmarshal(body, &res)
return res, err
}

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

var res ConfigResult
return res, json.Unmarshal(body, &res)
err = json.Unmarshal(body, &res)
return res, err
}

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

var res FlagsResult
return res, json.Unmarshal(body, &res)
err = json.Unmarshal(body, &res)
return res, err
}

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

var res BuildinfoResult
return res, json.Unmarshal(body, &res)
err = json.Unmarshal(body, &res)
return res, err
}

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

var res RuntimeinfoResult
return res, json.Unmarshal(body, &res)
err = json.Unmarshal(body, &res)
return res, err
}

func (h *httpAPI) LabelNames(ctx context.Context, matches []string, startTime, endTime time.Time) ([]string, Warnings, error) {
Expand All @@ -1036,7 +1042,8 @@ func (h *httpAPI) LabelNames(ctx context.Context, matches []string, startTime, e
return nil, w, err
}
var labelNames []string
return labelNames, w, json.Unmarshal(body, &labelNames)
err = json.Unmarshal(body, &labelNames)
return labelNames, w, err
}

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

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

var mset []model.LabelSet
return mset, warnings, json.Unmarshal(body, &mset)
err = json.Unmarshal(body, &mset)
return mset, warnings, err
}

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

var res SnapshotResult
return res, json.Unmarshal(body, &res)
err = json.Unmarshal(body, &res)
return res, err
}

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

var res RulesResult
return res, json.Unmarshal(body, &res)
err = json.Unmarshal(body, &res)
return res, err
}

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

var res TargetsResult
return res, json.Unmarshal(body, &res)
err = json.Unmarshal(body, &res)
return res, err
}

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

var res []MetricMetadata
return res, json.Unmarshal(body, &res)
err = json.Unmarshal(body, &res)
return res, err
}

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

var res map[string][]Metadata
return res, json.Unmarshal(body, &res)
err = json.Unmarshal(body, &res)
return res, err
}

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

var res TSDBResult
return res, json.Unmarshal(body, &res)
err = json.Unmarshal(body, &res)
return res, err
}

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

var res WalReplayStatus
return res, json.Unmarshal(body, &res)
err = json.Unmarshal(body, &res)
return res, err
}

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

var res []ExemplarQueryResult
return res, json.Unmarshal(body, &res)
err = json.Unmarshal(body, &res)
return res, err
}

// Warnings is an array of non critical errors
Expand Down