github-vet / github-vet/rangeloop-pointer-findings

anmolbabu/rds_metrics: metrics/helper.go; 36 LoC

Open
#6,991 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [anmolbabu/rds_metrics](https://www.github.com/anmolbabu/rds_metrics) at [metrics/helper.go](https://github.com/anmolbabu/rds_metrics/blob/9fc14db7b5964e3d1aa37c38588765271afeeb23/metrics/helper.go#L84-L119)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first
issue it finds, so please do not limit your consideration to the contents of the below message.

> range-loop variable metricFetcher used in defer or goroutine at line 87

[Click here to see the code in its original context.](https://github.com/anmolbabu/rds_metrics/blob/9fc14db7b5964e3d1aa37c38588765271afeeb23/metrics/helper.go#L84-L119)

Click here to show the 36 line(s) of Go which triggered the analyzer.

```go
for _, metricFetcher := range MetricFetchers {
go func() {
// execute the metricfetcher to get its corresponding clouwatch form
namespace, name, value, metaInfo, e := metricFetcher()
// if err is not nil, accummulate it and error and later instead of failing fast...
// So, that other metrics can be collected instead of failing completely for failure in collecting one/some
// of the metrics
if e != nil {
if err == nil {
err = e
return
} else {
err = fmt.Errorf("%s.%s", err, e.Error())
return
}
}

fmt.Println(namespace, name, value, metaInfo, e)

// Push the metric just collected
e = PushMetricToCloudWatch(namespace, name, value, metaInfo)
// If error accummulate error
if e != nil {
// ToDo(@Anmol Babu) handle the error concatenation better
if err == nil {
err = e
return
} else {
err = fmt.Errorf("%s.%s", err, e.Error())
return
}
}
// Signal completion of one routine to be waited on
wg.Done()
}()
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: 9fc14db7b5964e3d1aa37c38588765271afeeb23

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.