Skip to content

Commit 65b52a8

Browse files
authored
refactor: replace "wrapf" calls with stdlib wrap calls (#1275)
There is no need to keep the legacy "wrapf" calls to wrap errors anymore, so the idea is to remove them in favor of the wrapping calls of the stdlib. SANDBOX-1282
1 parent 88eb7f8 commit 65b52a8

5 files changed

Lines changed: 13 additions & 17 deletions

File tree

setup/metrics/gather.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
cfg "github.com/codeready-toolchain/toolchain-e2e/setup/configuration"
1212
"github.com/codeready-toolchain/toolchain-e2e/setup/metrics/queries"
1313
"github.com/codeready-toolchain/toolchain-e2e/setup/terminal"
14-
"github.com/pkg/errors"
1514
"github.com/prometheus/common/model"
1615

1716
k8sutil "k8s.io/apimachinery/pkg/util/wait"
@@ -124,13 +123,13 @@ func (g *Gatherer) sample(q queries.Query) error {
124123
if strings.Contains(err.Error(), "client error: 403") {
125124
url, tokenErr := auth.GetTokenRequestURI(g.k8sClient)
126125
if tokenErr != nil {
127-
return errors.Wrapf(err, "metrics query failed with 403 (Forbidden)")
126+
return fmt.Errorf("metrics query failed with 403 (Forbidden): %w", err)
128127
}
129-
return errors.Wrapf(err, "metrics query failed with 403 (Forbidden) - retrieve a new token from %s", url)
128+
return fmt.Errorf("metrics query failed with 403 (Forbidden) - retrieve a new token from %s: %w", url, err)
130129
}
131-
return errors.Wrapf(err, "metrics query failed - check whether prometheus is still healthy in the cluster")
130+
return fmt.Errorf("metrics query failed - check whether prometheus is still healthy in the cluster: %w", err)
132131
} else if len(warnings) > 0 {
133-
return errors.Wrapf(fmt.Errorf("warnings: %v", warnings), "metrics query had unexpected warnings")
132+
return fmt.Errorf("metrics query had unexpected warnings: %w", fmt.Errorf("warnings: %v", warnings))
134133
}
135134

136135
vector := val.(model.Vector)

setup/operators/operators.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
ctemplate "github.com/codeready-toolchain/toolchain-common/pkg/template"
1414
"github.com/operator-framework/api/pkg/operators/v1alpha1"
15-
"github.com/pkg/errors"
1615
"k8s.io/apimachinery/pkg/runtime"
1716
"sigs.k8s.io/controller-runtime/pkg/client"
1817
)
@@ -68,7 +67,7 @@ func EnsureOperatorsInstalled(ctx context.Context, cl client.Client, s *runtime.
6867
for _, templatePath := range templatePaths {
6968
tmpl, err := templates.GetTemplateFromFile(templatePath)
7069
if err != nil {
71-
return errors.Wrapf(err, "invalid template file: '%s'", templatePath)
70+
return fmt.Errorf("invalid template file: '%s': %w", templatePath, err)
7271
}
7372

7473
processor := ctemplate.NewProcessor(s)
@@ -135,10 +134,10 @@ func EnsureOperatorsInstalled(ctx context.Context, cl client.Client, s *runtime.
135134
}
136135
installDuration := time.Since(startTime)
137136
if csverr != nil {
138-
return errors.Wrapf(csverr, "failed to find CSV '%s' with Phase 'Succeeded'", currentCSV)
137+
return fmt.Errorf("failed to find CSV '%s' with Phase 'Succeeded': %w", currentCSV, csverr)
139138
}
140139
if err != nil {
141-
return errors.Wrapf(err, "failed to verify installation of operator with subscription '%s' after %s", subscriptionResource.GetName(), installDuration.String())
140+
return fmt.Errorf("failed to verify installation of operator with subscription '%s' after %s: %w", subscriptionResource.GetName(), installDuration.String(), err)
142141
}
143142

144143
fmt.Printf("Verified installation of operator with subscription '%s' completed in %s\n\n", subscriptionResource.GetName(), installDuration.String())

setup/resources/create_resources.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
ctemplate "github.com/codeready-toolchain/toolchain-common/pkg/template"
88
"github.com/codeready-toolchain/toolchain-e2e/setup/templates"
99
"github.com/codeready-toolchain/toolchain-e2e/setup/wait"
10-
"github.com/pkg/errors"
1110

1211
templatev1 "github.com/openshift/api/template/v1"
1312
"k8s.io/apimachinery/pkg/runtime"
@@ -26,7 +25,7 @@ func CreateUserResourcesFromTemplateFiles(ctx context.Context, cl runtimeclient.
2625
if _, ok := tmpls[templatePath]; !ok {
2726
var err error
2827
if tmpls[templatePath], err = templates.GetTemplateFromFile(templatePath); err != nil {
29-
return errors.Wrapf(err, "invalid template file: '%s'", templatePath)
28+
return fmt.Errorf("invalid template file: '%s': %w", templatePath, err)
3029
}
3130
}
3231
tmpl := tmpls[templatePath]

setup/templates/template.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
cfg "github.com/codeready-toolchain/toolchain-e2e/setup/configuration"
1313
multierror "github.com/hashicorp/go-multierror"
1414
templatev1 "github.com/openshift/api/template/v1"
15-
"github.com/pkg/errors"
1615
"k8s.io/apimachinery/pkg/runtime/serializer"
1716
k8swait "k8s.io/apimachinery/pkg/util/wait"
1817
"k8s.io/kubectl/pkg/scheme"
@@ -148,7 +147,7 @@ func applyObject(ctx context.Context, applycl *applyclientlib.SSAApplyClient, ob
148147
}
149148
return true, nil
150149
}); err != nil {
151-
return errors.Wrapf(err, "could not apply resource '%s' in namespace '%s'", obj.GetName(), obj.GetNamespace())
150+
return fmt.Errorf("could not apply resource '%s' in namespace '%s': %w", obj.GetName(), obj.GetNamespace(), err)
152151
}
153152
return nil
154153
}

setup/wait/wait.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package wait
22

33
import (
44
"context"
5+
"fmt"
56
"time"
67

78
"github.com/codeready-toolchain/toolchain-common/pkg/test"
89
"github.com/codeready-toolchain/toolchain-e2e/setup/configuration"
910

1011
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
1112
"github.com/operator-framework/api/pkg/operators/v1alpha1"
12-
"github.com/pkg/errors"
1313
corev1 "k8s.io/api/core/v1"
1414
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1515
"k8s.io/apimachinery/pkg/types"
@@ -41,7 +41,7 @@ func ForSpace(cl client.Client, space string) error {
4141
}
4242
return true, nil
4343
}); err != nil {
44-
return errors.Wrapf(err, "space '%s' is not ready yet", space)
44+
return fmt.Errorf("space '%s' is not ready yet: %w", space, err)
4545
}
4646
return nil
4747
}
@@ -67,7 +67,7 @@ func ForSubscriptionWithCriteria(cl client.Client, name, namespace string, timeo
6767
if err := k8swait.PollUntilContextTimeout(context.TODO(), configuration.DefaultRetryInterval, timeout, true, func(ctx context.Context) (bool, error) {
6868
return HasSubscriptionWithCriteria(cl, name, namespace, criteria...)
6969
}); err != nil {
70-
return errors.Wrapf(err, "could not find a Subscription with name '%s' in namespace '%s' that meets the expected criteria", name, namespace)
70+
return fmt.Errorf("could not find a Subscription with name '%s' in namespace '%s' that meets the expected criteria: %w", name, namespace, err)
7171
}
7272
return nil
7373
}
@@ -93,7 +93,7 @@ func ForCSVWithCriteria(cl client.Client, name, namespace string, timeout time.D
9393
if err := k8swait.PollUntilContextTimeout(context.TODO(), configuration.DefaultRetryInterval, timeout, true, func(ctx context.Context) (bool, error) {
9494
return HasCSVWithCriteria(cl, name, namespace, criteria...)
9595
}); err != nil {
96-
return errors.Wrapf(err, "could not find a CSV with name '%s' in namespace '%s' that meets the expected criteria", name, namespace)
96+
return fmt.Errorf("could not find a CSV with name '%s' in namespace '%s' that meets the expected criteria: %w", name, namespace, err)
9797
}
9898
return nil
9999
}

0 commit comments

Comments
 (0)