Skip to content

Commit c99487a

Browse files
Anand Kumarclaude
andcommitted
Start fixing err113 issues: add static errors and nolint for tests
- Define ErrTypeConversion static error in common/client.go - Update import to use apierrors for k8s errors - Add nolint directives for test files that use dynamic errors for testing This is the first step in addressing 50 err113 issues. Test files use dynamic errors to match production error messages, so nolint is appropriate. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 37735b7 commit c99487a

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

pkg/controller/certmanager/credentials_request_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//nolint:err113 // test file uses dynamic errors to match production error messages
12
package certmanager
23

34
import (

pkg/controller/common/client.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@ package common
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"reflect"
78

8-
"k8s.io/apimachinery/pkg/api/errors"
9+
apierrors "k8s.io/apimachinery/pkg/api/errors"
910
"k8s.io/client-go/util/retry"
1011

1112
"sigs.k8s.io/controller-runtime/pkg/client"
1213
"sigs.k8s.io/controller-runtime/pkg/manager"
1314
)
1415

16+
var (
17+
// ErrTypeConversion indicates a type conversion failure.
18+
ErrTypeConversion = errors.New("failed to convert to client.Object")
19+
)
20+
1521
// ctrlClientImpl implements the CtrlClient interface using the manager's client.
1622
type ctrlClientImpl struct {
1723
client.Client
@@ -100,7 +106,7 @@ func (c *ctrlClientImpl) UpdateWithRetry(
100106
currentInterface := reflect.New(reflect.TypeOf(obj).Elem()).Interface()
101107
current, ok := currentInterface.(client.Object)
102108
if !ok {
103-
return fmt.Errorf("failed to convert to client.Object")
109+
return ErrTypeConversion
104110
}
105111
if err := c.Client.Get(ctx, key, current); err != nil {
106112
return fmt.Errorf("failed to fetch latest %q for update: %w", key, err)
@@ -139,7 +145,7 @@ func (c *ctrlClientImpl) Patch(
139145

140146
func (c *ctrlClientImpl) Exists(ctx context.Context, key client.ObjectKey, obj client.Object) (bool, error) {
141147
if err := c.Client.Get(ctx, key, obj); err != nil {
142-
if errors.IsNotFound(err) {
148+
if apierrors.IsNotFound(err) {
143149
return false, nil
144150
}
145151
return false, err

pkg/controller/common/errors_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//nolint:err113 // test file uses dynamic errors for simplicity
12
package common
23

34
import (

0 commit comments

Comments
 (0)