Skip to content

Commit eda49ae

Browse files
authored
chore: enable errchkjson linter (#4329)
1 parent 5119075 commit eda49ae

File tree

6 files changed

+14
-41
lines changed

6 files changed

+14
-41
lines changed

.golangci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ linters:
88
#- contextcheck
99
- depguard
1010
- errcheck
11-
#- errchkjson
11+
- errchkjson
1212
#- errname
1313
#- gochecknoinits
1414
- gci

cmd/gitops/get/config/cmd.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ func getConfigCommandRunE(opts *cfg.Options) func(*cobra.Command, []string) erro
4141

4242
log.Successf("Your CLI configuration for Weave GitOps:")
4343

44-
cfgStr, err := gitopsConfig.String()
45-
if err != nil {
46-
log.Failuref("Error printing config")
47-
return err
48-
}
49-
44+
cfgStr := gitopsConfig.String()
5045
fmt.Println(cfgStr)
5146

5247
return nil

pkg/config/config.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,9 @@ type GitopsCLIConfig struct {
3131
UserID string `json:"userId"`
3232
}
3333

34-
func (config *GitopsCLIConfig) String() (string, error) {
35-
data, err := json.MarshalIndent(&config, "", " ")
36-
if err != nil {
37-
return "", fmt.Errorf("error encoding config: %w", err)
38-
}
39-
40-
return string(data), nil
34+
func (config *GitopsCLIConfig) String() string {
35+
data, _ := json.MarshalIndent(&config, "", " ")
36+
return string(data)
4137
}
4238

4339
// SetConfig sets global config to the provided value
@@ -94,10 +90,7 @@ func SaveConfig(config *GitopsCLIConfig) error {
9490
return err
9591
}
9692

97-
data, err := json.MarshalIndent(&config, "", " ")
98-
if err != nil {
99-
return fmt.Errorf("error encoding config: %w", err)
100-
}
93+
data, _ := json.MarshalIndent(&config, "", " ")
10194

10295
configFile, err := openConfigFile(configPath, true)
10396
if err != nil {

pkg/logger/s3_log_writer.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ func (l *S3LogWriter) putLog(msg string) {
6767
Message: msg,
6868
}
6969

70-
logData, err := json.Marshal(result)
71-
if err != nil {
72-
l.log0.Failuref("failed to marshal log data to JSON: %v", err)
73-
}
70+
logData, _ := json.Marshal(result)
7471

7572
// append new line at the end of each log
7673
logMsg := string(logData) + "\n"

pkg/server/auth/server.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -556,13 +556,9 @@ func (s *AuthServer) Refresh(rw http.ResponseWriter, r *http.Request) (*UserPrin
556556
}
557557

558558
func toJSON(rw http.ResponseWriter, ui UserInfo, log logr.Logger) {
559-
b, err := json.Marshal(ui)
560-
if err != nil {
561-
JSONError(log, rw, fmt.Sprintf("failed to marshal to JSON: %v", err), http.StatusInternalServerError)
562-
return
563-
}
559+
b, _ := json.Marshal(ui)
564560

565-
_, err = rw.Write(b)
561+
_, err := rw.Write(b)
566562
if err != nil {
567563
log.Error(err, "Failing to write response")
568564
}
@@ -581,14 +577,10 @@ func (s *AuthServer) startAuthFlow(rw http.ResponseWriter, r *http.Request) {
581577
returnURL = r.URL.String()
582578
}
583579

584-
b, err := json.Marshal(SessionState{
580+
b, _ := json.Marshal(SessionState{
585581
Nonce: nonce,
586582
ReturnURL: returnURL,
587583
})
588-
if err != nil {
589-
JSONError(s.Log, rw, fmt.Sprintf("failed to marshal state to JSON: %v", err), http.StatusInternalServerError)
590-
return
591-
}
592584

593585
state := base64.StdEncoding.EncodeToString(b)
594586

pkg/server/auth/server_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ func TestSignInNoSecret(t *testing.T) {
233233

234234
s, _ := makeAuthServer(t, ctrlclientfake.NewClientBuilder().Build(), tokenSignerVerifier, []auth.AuthMethod{auth.OIDC}, &fakeSessionManager{})
235235

236-
j, err := json.Marshal(auth.LoginRequest{})
237-
g.Expect(err).NotTo(HaveOccurred())
236+
j, _ := json.Marshal(auth.LoginRequest{})
238237

239238
reader := bytes.NewReader(j)
240239

@@ -277,8 +276,7 @@ func TestSignInWrongUsernameReturnsUnauthorized(t *testing.T) {
277276
Password: "my-secret-password",
278277
}
279278

280-
j, err := json.Marshal(login)
281-
g.Expect(err).NotTo(HaveOccurred())
279+
j, _ := json.Marshal(login)
282280

283281
reader := bytes.NewReader(j)
284282

@@ -318,8 +316,7 @@ func TestSignInWrongPasswordReturnsUnauthorized(t *testing.T) {
318316
Password: "wrong",
319317
}
320318

321-
j, err := json.Marshal(login)
322-
g.Expect(err).NotTo(HaveOccurred())
319+
j, _ := json.Marshal(login)
323320

324321
reader := bytes.NewReader(j)
325322

@@ -358,8 +355,7 @@ func TestSignInCorrectPassword(t *testing.T) {
358355
Password: password,
359356
}
360357

361-
j, err := json.Marshal(login)
362-
g.Expect(err).NotTo(HaveOccurred())
358+
j, _ := json.Marshal(login)
363359

364360
reader := bytes.NewReader(j)
365361

0 commit comments

Comments
 (0)