Skip to content

Commit a5cd8f9

Browse files
committed
Enable the "errchkjson" linter
This is part of the "bugs" preset of golangci-lint. The "check-error-free-encoding" setting is recommended upstream.
1 parent 561c650 commit a5cd8f9

File tree

7 files changed

+12
-25
lines changed

7 files changed

+12
-25
lines changed

.golangci.next.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ linters:
1010
enable:
1111
- contextcheck
1212
- err113
13-
- errchkjson
1413
- gocritic
1514
- godot
1615
- godox
@@ -31,9 +30,6 @@ issues:
3130
exclude-use-default: false
3231

3332
linters-settings:
34-
errchkjson:
35-
check-error-free-encoding: true
36-
3733
thelper:
3834
# https://github.com/kulti/thelper/issues/27
3935
tb: { begin: true, first: true }

.golangci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
linters:
44
disable:
55
- contextcheck
6-
- errchkjson
76
- gci
87
- gofumpt
98
enable:
@@ -41,6 +40,9 @@ linters-settings:
4140
- pkg: github.com/crunchydata/postgres-operator/internal/testing/*
4241
desc: The "internal/testing" packages should be used only in tests.
4342

43+
errchkjson:
44+
check-error-free-encoding: true
45+
4446
exhaustive:
4547
default-signifies-exhaustive: true
4648

internal/bridge/client.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -724,10 +724,7 @@ func (c *Client) UpdateCluster(
724724
) (*ClusterApiResource, error) {
725725
result := &ClusterApiResource{}
726726

727-
clusterbyte, err := json.Marshal(clusterRequestPayload)
728-
if err != nil {
729-
return result, err
730-
}
727+
clusterbyte, _ := json.Marshal(clusterRequestPayload)
731728

732729
response, err := c.doWithRetry(ctx, "PATCH", "/clusters/"+id, nil, clusterbyte, http.Header{
733730
"Accept": []string{"application/json"},

internal/controller/standalone_pgadmin/users.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,7 @@ cd $PGADMIN_DIR
293293
// to add a user, that user will not be in intentUsers. If errors occurred when attempting to
294294
// update a user, the user will be in intentUsers as it existed before. We now want to marshal the
295295
// intentUsers to json and write the users.json file to the secret.
296-
usersJSON, err := json.Marshal(intentUsers)
297-
if err != nil {
298-
return err
299-
}
300-
intentUserSecret.Data["users.json"] = usersJSON
296+
intentUserSecret.Data["users.json"], _ = json.Marshal(intentUsers)
301297

302298
err = errors.WithStack(r.setControllerReference(pgadmin, intentUserSecret))
303299
if err == nil {

internal/upgradecheck/header.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,8 @@ func getServerVersion(ctx context.Context, cfg *rest.Config) string {
209209
return versionInfo.String()
210210
}
211211

212-
func addHeader(req *http.Request, upgradeInfo *clientUpgradeData) (*http.Request, error) {
213-
marshaled, err := json.Marshal(upgradeInfo)
214-
if err == nil {
215-
upgradeInfoString := string(marshaled)
216-
req.Header.Add(clientHeader, upgradeInfoString)
217-
}
218-
return req, err
212+
func addHeader(req *http.Request, upgradeInfo *clientUpgradeData) *http.Request {
213+
marshaled, _ := json.Marshal(upgradeInfo)
214+
req.Header.Add(clientHeader, string(marshaled))
215+
return req
219216
}

internal/upgradecheck/header_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,11 @@ func TestAddHeader(t *testing.T) {
596596
PGOVersion: versionString,
597597
}
598598

599-
result, err := addHeader(req, upgradeInfo)
600-
assert.NilError(t, err)
599+
result := addHeader(req, upgradeInfo)
601600
header := result.Header[clientHeader]
602601

603602
passedThroughData := &clientUpgradeData{}
604-
err = json.Unmarshal([]byte(header[0]), passedThroughData)
603+
err := json.Unmarshal([]byte(header[0]), passedThroughData)
605604
assert.NilError(t, err)
606605

607606
assert.Equal(t, passedThroughData.PGOVersion, "1.2.3")

internal/upgradecheck/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func checkForUpgrades(ctx context.Context, url, versionString string, backoff wa
7777
// in case some of the checks return errors
7878
headerPayloadStruct = generateHeader(ctx, cfg, crclient,
7979
versionString, isOpenShift, registrationToken)
80-
req, err = addHeader(req, headerPayloadStruct)
80+
req = addHeader(req, headerPayloadStruct)
8181
}
8282

8383
// wait.ExponentialBackoff will retry the func according to the backoff object until

0 commit comments

Comments
 (0)