Skip to content

Commit f5bafc9

Browse files
agb-cloudclaude
andcommitted
fix: resolve all golangci-lint errors
Fix multiple linter issues to pass CI/CD checks: - errcheck: Add error handling for w.Write(), cfg.ClearTokens(), and buf.ReadFrom() calls - unused: Remove unused variable 'nl' in cmd/image.go - ineffassign: Fix ineffectual assignment to contentType in detectContentType() - staticcheck SA1019: Replace deprecated netErr.Temporary() with timeout check - staticcheck SA4020: Reorder switch cases to avoid unreachable code (interface{} matches all) - staticcheck SA9003: Clarify empty branch comment in retry delay logic 🤖 Generated with [Claude Code] Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1f37bb5 commit f5bafc9

8 files changed

Lines changed: 21 additions & 19 deletions

File tree

cmd/image.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ func getNewline() string {
4040
return "\n"
4141
}
4242

43-
// nl is a convenience variable for newline
44-
var nl = getNewline()
45-
4643
var ImageCmd = &cobra.Command{
4744
Use: "image",
4845
Short: "Manage images",

internal/auth/auth.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ func StartCallbackServer(ctx context.Context, port string) (string, error) {
5656
// Return success page
5757
w.Header().Set("Content-Type", "text/html")
5858
w.WriteHeader(http.StatusOK)
59-
w.Write([]byte(GetSuccessHTML()))
59+
if _, writeErr := w.Write([]byte(GetSuccessHTML())); writeErr != nil {
60+
// Log the error but don't fail the authentication
61+
// The code has already been captured successfully
62+
err = fmt.Errorf("warning: failed to write success page: %w", writeErr)
63+
}
6064

6165
// Delay server close to ensure browser receives the success page
6266
go func() {

internal/auth/token_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ func RefreshTokenIfNeeded(ctx context.Context) error {
4444
cfg.Token.SessionId)
4545
if err != nil {
4646
// If refresh fails, clear the tokens
47-
cfg.ClearTokens()
47+
_ = cfg.ClearTokens() // Ignore error as we're already returning the refresh error
4848
return fmt.Errorf("use 'agbcloud-cli login' to reauthenticate: %w", err)
4949
}
5050

5151
if !response.Success {
5252
// If refresh fails, clear the tokens
53-
cfg.ClearTokens()
53+
_ = cfg.ClearTokens() // Ignore error as we're already returning the refresh error
5454
return fmt.Errorf("use 'agbcloud-cli login' to reauthenticate: refresh failed with code %s", response.Code)
5555
}
5656

internal/client/client.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,15 @@ func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err e
272272
func detectContentType(body interface{}) string {
273273
contentType := "text/plain; charset=utf-8"
274274
switch body.(type) {
275-
case map[string]interface{}, []interface{}, interface{}:
276-
contentType = "application/json; charset=utf-8"
277275
case string:
278-
contentType = "text/plain; charset=utf-8"
276+
// Already set to text/plain by default, no need to reassign
277+
case []byte:
278+
contentType = http.DetectContentType(body.([]byte))
279+
case map[string]interface{}, []interface{}:
280+
contentType = "application/json; charset=utf-8"
279281
default:
280-
if b, ok := body.([]byte); ok {
281-
contentType = http.DetectContentType(b)
282-
} else {
283-
contentType = "application/json; charset=utf-8"
284-
}
282+
// For any other type, assume JSON
283+
contentType = "application/json; charset=utf-8"
285284
}
286285

287286
return contentType

internal/client/retry.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ func IsRetryableError(err error) bool {
7676
}
7777

7878
// Check for specific error types
79+
// Note: netErr.Temporary() is deprecated since Go 1.18
80+
// We rely on string matching and timeout checks instead
7981
if netErr, ok := err.(net.Error); ok {
80-
return netErr.Temporary() || netErr.Timeout()
82+
return netErr.Timeout()
8183
}
8284

8385
// Check for syscall errors
@@ -189,7 +191,7 @@ func (r *RetryableHTTPClient) Do(req *http.Request) (*http.Response, error) {
189191

190192
select {
191193
case <-time.After(delay):
192-
// Continue to next attempt
194+
// Delay elapsed, continue to next attempt
193195
case <-req.Context().Done():
194196
return nil, req.Context().Err()
195197
}

test/unit/cpu_memory_validation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func captureStderrCPU(f func()) string {
2424
os.Stderr = oldStderr
2525

2626
var buf bytes.Buffer
27-
buf.ReadFrom(r)
27+
_, _ = buf.ReadFrom(r) // Ignore errors in test helper
2828
return buf.String()
2929
}
3030

test/unit/error_message_formatting_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func captureStderrErr(f func()) string {
2626
os.Stderr = oldStderr
2727

2828
var buf bytes.Buffer
29-
buf.ReadFrom(r)
29+
_, _ = buf.ReadFrom(r) // Ignore errors in test helper
3030
return buf.String()
3131
}
3232

test/unit/image_cmd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func captureStderr(f func()) string {
2828
os.Stderr = oldStderr
2929

3030
var buf bytes.Buffer
31-
buf.ReadFrom(r)
31+
_, _ = buf.ReadFrom(r) // Ignore errors in test helper
3232
return buf.String()
3333
}
3434

0 commit comments

Comments
 (0)