Skip to content

Fix invalid ErrWrappingFormat usage with multiple %w verbs in fmt.Errorf calls #1476

@coderabbitai

Description

@coderabbitai

Problem

The current codebase uses ErrWrappingFormat (defined as "%w: %w") in fmt.Errorf calls, which violates Go's rule that only one %w verb is allowed per format string. This creates invalid error wrapping patterns that can fail go vet and behave unexpectedly.

Root Cause

In errors/errors.go:

ErrWrappingFormat = "%w: %w"  // ❌ Invalid - multiple %w verbs
ErrStringWrappingFormat = "%w: %s"  // ✅ Valid - single %w verb

Affected Files (16 occurrences across 8 files)

  • pkg/auth/cloud/aws/setup.go: 2 usages
  • pkg/auth/identities/aws/user.go: 2 usages
  • pkg/auth/types/github_oidc_credentials.go: 2 usages
  • pkg/auth/manager.go: 2 usages
  • pkg/config/load.go: 2 usages
  • internal/exec/terraform_generate_planfile.go: 3 usages
  • internal/exec/packer_output.go: 1 usage
  • cmd/auth_user.go: 2 usages

Solution

Replace all instances of ErrWrappingFormat with ErrStringWrappingFormat:

- fmt.Errorf(errUtils.ErrWrappingFormat, errUtils.ErrSomeError, err)
+ fmt.Errorf(errUtils.ErrStringWrappingFormat, errUtils.ErrSomeError, err)

This ensures:

  • Go vet compliance
  • Proper error wrapping with single %w verb
  • Consistent error handling patterns

Discovery Context

Discovered during code review in PR #1475: #1475 (comment)

Acceptance Criteria

  • Replace all 16 occurrences of ErrWrappingFormat with ErrStringWrappingFormat
  • Verify go vet passes on all affected files
  • Test error wrapping behavior remains correct

Metadata

Metadata

Assignees

Labels

bug🐛 An issue with the system

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions