Skip to content

Commit

Permalink
Enable errcheck linter rule (#2470)
Browse files Browse the repository at this point in the history
* Install the CodeSee workflow. Learn more at https://docs.codesee.io

* removed the codesee-arch-diagram.yml~

* enable errcheck linter on anew branch because old branch was not made from main branch

* made change in file proxy.go located at vmproxy/proxy/proxy.go

* made change in file admin/pkg/client/tarball/tarball.go located at admin/pkg/client/tarball/tarball.go

* made change in file proxy_test.go located at vmproxy/proxy/proxy_test.go

* made change in file proxy_test.go located at vmproxy/proxy/proxy_test.go

* made change in file database.go located at managed/services/dbaas/kubernetes/client/database/database.go

* made change in file percona_sso_model_helpers.go located at managed/models/percona_sso_model_helpers.go

* made change in file api-tests/server/auth_test.go located at api-tests/server/auth_test.go

* made change in file api-tests/server/auth_test.go located at api-tests/server/auth_test.go

* made change in file admin/commands/summary.go located at admin/commands/summary.go

* made change in file job_helpers_test.go located at managed/models/job_helpers_test.go

* made change in file datasources.go located at managed/services/telemetry/datasources.go

* made change in file datasources.go located at managed/services/telemetry/datasources.go

* made change in file main.go located at qan-api2/main.go

* made change in file main.go located at qan-api2/main.go

* made change in file pgstatmonitor.go located at agent/agents/postgres/pgstatmonitor/pgstatmonitor.go

* made change in file ports_registry_test.go located at agent/agents/supervisor/ports_registry_test.go

* made change in file victoriametrics.go located at managed/services/victoriametrics/victoriametrics.go

* made change in file readyz_test.go located at api-tests/server/readyz_test.go

* made change in file version_test.go located at api-tests/server/version_test.go

* made change in file client.go located at managed/utils/platform/client.go

* made change in file auth_server_test.go located at managed/services/grafana/auth_server_test.go

* made change in file auth_server_test.go located at managed/services/grafana/auth_server_test.go

* made change in file alertmanager.go located at managed/services/alertmanager/alertmanager.go

* made change in file inventory_metrics_test.go located at managed/services/inventory/inventory_metrics_test.go

* made change in file client.go located at managed/services/grafana/client.go

* made change in file connection_checker.go located at agent/connectionchecker/connection_checker.go

* made change in file vmalert.go located at managed/services/vmalert/vmalert.go

* made change in file vmalert.go located at managed/services/vmalert/vmalert.go

* made change in file metrics.go located at qan-api2/models/metrics.go

* changed database.go located at managed/services/dbaas/kubernetes/client/database/

* changed database.go located at managed/services/dbaas/kubernetes/client/database/

* removed commented errcheck linyter

* changes after make format

* made changes in managed/services/dbaas/kubernetes/client/client.go

* made changes in anaged/services/management/dbaas/components_service.go

* made changes in managed/services/management/dbaas/version_service_client.go

* mae\ke format changes done

---------

Co-authored-by: codesee-maps[bot] <86324825+codesee-maps[bot]@users.noreply.github.com>
Co-authored-by: Artem Gavrilov <artem.gavrilov@percona.com>
  • Loading branch information
3 people authored Oct 11, 2023
1 parent 3f4874b commit d974ff8
Show file tree
Hide file tree
Showing 29 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ linters:
- revive
- paralleltest
- gocognit
- errcheck

# ENDTODO

run:
Expand Down
6 changes: 3 additions & 3 deletions admin/commands/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func addFile(zipW *zip.Writer, name string, fileName string) {
logrus.Debugf("%s", err)
r = io.NopCloser(bytes.NewReader([]byte(err.Error() + "\n")))
}
defer r.Close() //nolint:gosec
defer r.Close() //nolint:gosec,errcheck

modTime := time.Now()
if fi, _ := os.Stat(fileName); fi != nil {
Expand Down Expand Up @@ -219,7 +219,7 @@ func addVMAgentTargets(ctx context.Context, zipW *zip.Writer, agentsInfo []*agen
addData(zipW, "client/vmagent-targets.html", now, bytes.NewReader([]byte(err.Error())))
return
}
defer res.Body.Close() //nolint:gosec
defer res.Body.Close() //nolint:gosec,errcheck
html, err = io.ReadAll(res.Body)
if err != nil {
logrus.Debugf("%s", err)
Expand All @@ -241,7 +241,7 @@ func getURL(ctx context.Context, url string) ([]byte, error) {
if err != nil {
return nil, errors.WithStack(err)
}
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

if resp.StatusCode != http.StatusOK {
return nil, errors.Errorf("status code: %d", resp.StatusCode)
Expand Down
2 changes: 1 addition & 1 deletion admin/pkg/client/tarball/tarball.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (b *Base) checksumTarball(ctx context.Context, link string, path string) er
return err
}

defer res.Body.Close() //nolint:gosec
defer res.Body.Close() //nolint:gosec,errcheck
if res.StatusCode != http.StatusOK {
return fmt.Errorf("%w: cannot download tarball's sha256sum (http %d)", ErrHTTPStatusNotOk, res.StatusCode)
}
Expand Down
2 changes: 1 addition & 1 deletion agent/agents/postgres/pgstatmonitor/pgstatmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func getPGSM20Settings(q *reform.Querier) (settings, error) {
if err != nil {
return nil, err
}
defer rows.Close()
defer rows.Close() //nolint:errcheck

result := make(settings)
for rows.Next() {
Expand Down
6 changes: 3 additions & 3 deletions agent/agents/supervisor/ports_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestRegistry(t *testing.T) {
r := newPortsRegistry(65000, 65002, []uint16{65000})
l1, err := net.Listen("tcp", "127.0.0.1:65001")
require.NoError(t, err)
defer l1.Close() //nolint:gosec
defer l1.Close() //nolint:gosec,errcheck

p, err := r.Reserve()
assert.NoError(t, err)
Expand All @@ -46,8 +46,8 @@ func TestRegistry(t *testing.T) {
err = r.Release(65002)
assert.Equal(t, errPortBusy, err)

l1.Close()
l2.Close()
l1.Close() //nolint:errcheck
l2.Close() //nolint:errcheck

p, err = r.Reserve()
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion agent/connectionchecker/connection_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (cc *ConnectionChecker) checkExternalConnection(ctx context.Context, uri st
res.Error = err.Error()
return &res
}
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

if resp.StatusCode != http.StatusOK {
res.Error = fmt.Sprintf("Unexpected HTTP status code: %d. Expected: 200", resp.StatusCode)
Expand Down
32 changes: 16 additions & 16 deletions api-tests/server/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestAuth(t *testing.T) {
req, _ := http.NewRequestWithContext(pmmapitests.Context, http.MethodGet, uri.String(), nil)
resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

b, err := httputil.DumpResponse(resp, true)
require.NoError(t, err)
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestSetup(t *testing.T) {
req.Header.Set("X-Test-Must-Setup", "1")

resp, b := doRequest(t, client, req)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

assert.Equal(t, 200, resp.StatusCode, "response:\n%s", b)
assert.True(t, strings.HasPrefix(string(b), `<!doctype html>`), string(b))
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestSetup(t *testing.T) {
req.Header.Set("X-Test-Must-Setup", "1")

resp, b := doRequest(t, client, req)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

assert.Equal(t, code, resp.StatusCode, "response:\n%s", b)
if code == 303 {
Expand All @@ -179,7 +179,7 @@ func TestSetup(t *testing.T) {
req.Header.Set("X-Test-Must-Setup", "1")

resp, b := doRequest(t, client, req)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

assert.Equal(t, 200, resp.StatusCode, "response:\n%s", b)
assert.Equal(t, "{}", string(b), "response:\n%s", b)
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestSwagger(t *testing.T) {
require.NoError(t, err)

resp, _ := doRequest(t, http.DefaultClient, req)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode)
Expand All @@ -231,7 +231,7 @@ func TestSwagger(t *testing.T) {
require.NoError(t, err)

resp, _ := doRequest(t, http.DefaultClient, req)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode)
Expand Down Expand Up @@ -318,7 +318,7 @@ func TestPermissions(t *testing.T) {

resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

assert.Equal(t, user.statusCode, resp.StatusCode)
})
Expand All @@ -340,7 +340,7 @@ func TestPermissions(t *testing.T) {

resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

assert.Equal(t, user.statusCode, resp.StatusCode)
})
Expand All @@ -360,7 +360,7 @@ func TestPermissions(t *testing.T) {

resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

assert.Equal(t, user.statusCode, resp.StatusCode)
})
Expand All @@ -374,7 +374,7 @@ func doRequest(tb testing.TB, client *http.Client, req *http.Request) (*http.Res
resp, err := client.Do(req)
require.NoError(tb, err)

defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

b, err := io.ReadAll(resp.Body)
require.NoError(tb, err)
Expand All @@ -400,7 +400,7 @@ func deleteUser(t *testing.T, userID int) {
require.NoError(t, err)

resp, b := doRequest(t, http.DefaultClient, req)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

require.Equalf(t, http.StatusOK, resp.StatusCode, "failed to delete user, status code: %d, response: %s", resp.StatusCode, b)
}
Expand All @@ -426,7 +426,7 @@ func createUser(t *testing.T, login string) int {
req.Header.Set("Content-Type", "application/json; charset=utf-8")

resp, b := doRequest(t, http.DefaultClient, req)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck
require.Equalf(t, http.StatusOK, resp.StatusCode, "failed to create user, status code: %d, response: %s", resp.StatusCode, b)

var m map[string]interface{}
Expand All @@ -453,7 +453,7 @@ func setRole(t *testing.T, userID int, role string) {

req.Header.Set("Content-Type", "application/json; charset=utf-8")
resp, b := doRequest(t, http.DefaultClient, req)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

require.Equalf(t, http.StatusOK, resp.StatusCode, "failed to set role for user, response: %s", b)
}
Expand All @@ -469,7 +469,7 @@ func deleteAPIKey(t *testing.T, apiKeyID int) {
require.NoError(t, err)

resp, b := doRequest(t, http.DefaultClient, req)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

require.Equalf(t, http.StatusOK, resp.StatusCode, "failed to delete API Key, status code: %d, response: %s", resp.StatusCode, b)
}
Expand All @@ -493,7 +493,7 @@ func createAPIKeyWithRole(t *testing.T, name, role string) (int, string) {
req.Header.Set("Content-Type", "application/json; charset=utf-8")

resp, b := doRequest(t, http.DefaultClient, req)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

require.Equalf(t, http.StatusOK, resp.StatusCode, "failed to create API key, status code: %d, response: %s", resp.StatusCode, b)

Expand All @@ -509,7 +509,7 @@ func createAPIKeyWithRole(t *testing.T, name, role string) (int, string) {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))

resp1, b := doRequest(t, http.DefaultClient, req)
defer resp1.Body.Close() //nolint:gosec
defer resp1.Body.Close() //nolint:gosec,errcheck

require.Equalf(t, http.StatusOK, resp1.StatusCode, "failed to get API key, status code: %d, response: %s", resp1.StatusCode, b)

Expand Down
2 changes: 1 addition & 1 deletion api-tests/server/readyz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestReadyz(t *testing.T) {
req, _ := http.NewRequestWithContext(pmmapitests.Context, http.MethodGet, uri.String(), nil)
resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

b, err := io.ReadAll(resp.Body)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion api-tests/server/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestVersion(t *testing.T) {
req, _ := http.NewRequestWithContext(pmmapitests.Context, http.MethodGet, uri.String(), nil)
resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

b, err := io.ReadAll(resp.Body)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion managed/models/job_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestJobs(t *testing.T) {
t.Run("find", func(t *testing.T) {
findTX, err := db.Begin()
require.NoError(t, err)
defer findTX.Rollback()
defer findTX.Rollback() //nolint:errcheck

const jobsCount = 3
jobs := make([]*models.Job, 0, jobsCount)
Expand Down
2 changes: 1 addition & 1 deletion managed/models/percona_sso_model_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *PerconaSSODetails) refreshAndGetAccessToken(ctx context.Context, q *ref
if err != nil {
return nil, err
}
defer res.Body.Close() //nolint:gosec
defer res.Body.Close() //nolint:gosec,errcheck

bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions managed/services/alertmanager/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (svc *Service) reload(ctx context.Context) error {
if err != nil {
return errors.WithStack(err)
}
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

b, err := io.ReadAll(resp.Body)
svc.l.Debugf("Alertmanager reload: %s", b)
Expand Down Expand Up @@ -859,7 +859,7 @@ func (svc *Service) IsReady(ctx context.Context) error {
if err != nil {
return errors.WithStack(err)
}
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

b, err := io.ReadAll(resp.Body)
svc.l.Debugf("Alertmanager ready: %s", b)
Expand Down
4 changes: 2 additions & 2 deletions managed/services/dbaas/kubernetes/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (c *Client) setup() error {
}
// Set PATH variable to make aws-iam-authenticator executable
path := fmt.Sprintf("%s:%s", os.Getenv("PATH"), dbaasToolPath)
os.Setenv("PATH", path)
os.Setenv("PATH", path) //nolint:errcheck
c.namespace = namespace
return c.initOperatorClients()
}
Expand Down Expand Up @@ -567,7 +567,7 @@ func tabbedString(f func(io.Writer) error) (string, error) {
return "", err
}

out.Flush()
out.Flush() //nolint:errcheck
str := buf.String()
return str, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewForConfig(c *rest.Config) (*DatabaseClusterClient, error) {
config.UserAgent = rest.DefaultKubernetesUserAgent()

addToScheme.Do(func() {
dbaasv1.SchemeBuilder.AddToScheme(scheme.Scheme)
dbaasv1.SchemeBuilder.AddToScheme(scheme.Scheme) //nolint:errcheck
metav1.AddToGroupVersion(scheme.Scheme, dbaasv1.GroupVersion)
})

Expand Down
8 changes: 4 additions & 4 deletions managed/services/grafana/auth_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestAuthServerMustSetup(t *testing.T) {
assert.True(t, s.mustSetup(rw, req, logrus.WithField("test", t.Name())))

resp := rw.Result()
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck
assert.Equal(t, 401, resp.StatusCode)
assert.Equal(t, "1", resp.Header.Get("X-Must-Setup"))
assert.Equal(t, "", resp.Header.Get("Location"))
Expand All @@ -97,7 +97,7 @@ func TestAuthServerMustSetup(t *testing.T) {
assert.True(t, s.mustSetup(rw, req, logrus.WithField("test", t.Name())))

resp := rw.Result()
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck
assert.Equal(t, 303, resp.StatusCode)
assert.Equal(t, "", resp.Header.Get("X-Must-Setup"))
assert.Equal(t, "/setup", resp.Header.Get("Location"))
Expand All @@ -123,7 +123,7 @@ func TestAuthServerMustSetup(t *testing.T) {
assert.False(t, s.mustSetup(rw, req, logrus.WithField("test", t.Name())))

resp := rw.Result()
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck
assert.Equal(t, 200, resp.StatusCode)
assert.Equal(t, "", resp.Header.Get("X-Must-Setup"))
assert.Equal(t, "", resp.Header.Get("Location"))
Expand All @@ -148,7 +148,7 @@ func TestAuthServerMustSetup(t *testing.T) {
assert.False(t, s.mustSetup(rw, req, logrus.WithField("test", t.Name())))

resp := rw.Result()
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck
assert.Equal(t, 200, resp.StatusCode)
assert.Equal(t, "", resp.Header.Get("X-Must-Setup"))
assert.Equal(t, "", resp.Header.Get("Location"))
Expand Down
2 changes: 1 addition & 1 deletion managed/services/grafana/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (c *Client) do(ctx context.Context, method, path, rawQuery string, headers
if err != nil {
return errors.WithStack(err)
}
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

b, err := io.ReadAll(resp.Body)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion managed/services/inventory/inventory_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestNewInventoryMetricsCollector(t *testing.T) {
require.NoError(t, err)
resp, err := client.Do(req)
require.NoError(t, err)
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions managed/services/management/dbaas/components_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ func imageExists(ctx context.Context, image string) (bool, error) {
if err != nil {
panic(err)
}
defer cli.Close()
defer cli.Close() //nolint:errcheck

reader, err := cli.ImagePull(ctx, image, types.ImagePullOptions{})
if err != nil {
Expand All @@ -548,7 +548,7 @@ func imageExists(ctx context.Context, image string) (bool, error) {
return false, err
}

reader.Close()
reader.Close() //nolint:errcheck

return true, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (c *VersionServiceClient) Matrix(ctx context.Context, params componentsPara
if err != nil {
return nil, err
}
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion managed/services/supervisord/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func readURL(ctx context.Context, url string) ([]byte, error) {
if err != nil {
return nil, errors.WithStack(err)
}
defer resp.Body.Close() //nolint:gosec
defer resp.Body.Close() //nolint:gosec,errcheck

b, err := io.ReadAll(resp.Body)
if err != nil {
Expand Down
Loading

0 comments on commit d974ff8

Please sign in to comment.