Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

chore: remove dependency on unmaintained 'errors' package (#490) #509

Merged
merged 5 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/google/go-github/v35 v35.0.0
github.com/imdario/mergo v0.3.12
github.com/jeremywohl/flatten v1.0.1
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
github.com/valyala/fasttemplate v1.2.1
Expand Down
11 changes: 5 additions & 6 deletions pkg/controllers/applicationset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controllers
import (
"context"
"encoding/json"
"errors"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -103,7 +102,7 @@ func TestExtractApplications(t *testing.T) {
},
{
name: "Handles error from the generator",
generateParamsError: errors.New("error"),
generateParamsError: fmt.Errorf("error"),
expectErr: true,
expectedReason: v1alpha1.ApplicationSetReasonApplicationParamsGenerationError,
},
Expand All @@ -118,7 +117,7 @@ func TestExtractApplications(t *testing.T) {
},
Spec: argov1alpha1.ApplicationSpec{},
},
rendererError: errors.New("error"),
rendererError: fmt.Errorf("error"),
expectErr: true,
expectedReason: v1alpha1.ApplicationSetReasonRenderTemplateParamsError,
},
Expand Down Expand Up @@ -1620,7 +1619,7 @@ func TestValidateGeneratedApplications(t *testing.T) {
},
},
expectedErrors: []string{"application destination can't have both name and server defined"},
validationErrors: map[int]error{0: errors.New("application destination spec is invalid: application destination can't have both name and server defined: my-cluster my-server")},
validationErrors: map[int]error{0: fmt.Errorf("application destination spec is invalid: application destination can't have both name and server defined: my-cluster my-server")},
},
{
name: "project mismatch should return error",
Expand All @@ -1643,7 +1642,7 @@ func TestValidateGeneratedApplications(t *testing.T) {
},
},
expectedErrors: []string{"application references project DOES-NOT-EXIST which does not exist"},
validationErrors: map[int]error{0: errors.New("application references project DOES-NOT-EXIST which does not exist")},
validationErrors: map[int]error{0: fmt.Errorf("application references project DOES-NOT-EXIST which does not exist")},
},
{
name: "valid app should return true",
Expand Down Expand Up @@ -1689,7 +1688,7 @@ func TestValidateGeneratedApplications(t *testing.T) {
},
},
expectedErrors: []string{"there are no clusters with this name: nonexistent-cluster"},
validationErrors: map[int]error{0: errors.New("application destination spec is invalid: unable to find destination server: there are no clusters with this name: nonexistent-cluster")},
validationErrors: map[int]error{0: fmt.Errorf("application destination spec is invalid: unable to find destination server: there are no clusters with this name: nonexistent-cluster")},
},
} {

Expand Down
6 changes: 3 additions & 3 deletions pkg/generators/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package generators

import (
"context"
"errors"
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -25,7 +25,7 @@ type possiblyErroringFakeCtrlRuntimeClient struct {

func (p *possiblyErroringFakeCtrlRuntimeClient) List(ctx context.Context, secretList client.ObjectList, opts ...client.ListOption) error {
if p.shouldError {
return errors.New("could not list Secrets")
return fmt.Errorf("could not list Secrets")
}
return p.Client.List(ctx, secretList, opts...)
}
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestGenerateParams(t *testing.T) {
values: nil,
expected: nil,
clientError: true,
expectedError: errors.New("could not list Secrets"),
expectedError: fmt.Errorf("could not list Secrets"),
},
}

Expand Down
7 changes: 3 additions & 4 deletions pkg/generators/duck_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package generators

import (
"context"
"errors"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -98,14 +97,14 @@ func (g *DuckTypeGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.A
// Validate the fields
if kind == "" || versionIdx < 1 {
log.Warningf("kind=%v, resourceName=%v, versionIdx=%v", kind, resourceName, versionIdx)
return nil, errors.New("There is a problem with the apiVersion, kind or resourceName provided")
return nil, fmt.Errorf("There is a problem with the apiVersion, kind or resourceName provided")
}

if (resourceName == "" && labelSelector.MatchLabels == nil && labelSelector.MatchExpressions == nil) ||
(resourceName != "" && (labelSelector.MatchExpressions != nil || labelSelector.MatchLabels != nil)) {

log.Warningf("You must choose either resourceName=%v, labelSelector.matchLabels=%v or labelSelect.matchExpressions=%v", resourceName, labelSelector.MatchLabels, labelSelector.MatchExpressions)
return nil, errors.New("There is a problem with the definition of the ClusterDecisionResource generator")
return nil, fmt.Errorf("There is a problem with the definition of the ClusterDecisionResource generator")
}

// Split up the apiVersion
Expand Down Expand Up @@ -134,7 +133,7 @@ func (g *DuckTypeGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.A

if len(duckResources.Items) == 0 {
log.Warning("no resource found, make sure you clusterDecisionResource is defined correctly")
return nil, errors.New("no clusterDecisionResources found")
return nil, fmt.Errorf("no clusterDecisionResources found")
}

// Override the duck type in the status of the resource
Expand Down
8 changes: 4 additions & 4 deletions pkg/generators/duck_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package generators

import (
"context"
"errors"
"fmt"

argoprojiov1alpha1 "github.com/argoproj/applicationset/api/v1alpha1"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestGenerateParamsForDuckType(t *testing.T) {
resource: duckType,
values: nil,
expected: []map[string]string{},
expectedError: errors.New("There is a problem with the definition of the ClusterDecisionResource generator"),
expectedError: fmt.Errorf("There is a problem with the definition of the ClusterDecisionResource generator"),
},
/*** This does not work with the FAKE runtime client, fieldSelectors are broken.
{
Expand All @@ -166,7 +166,7 @@ func TestGenerateParamsForDuckType(t *testing.T) {
resource: duckType,
values: nil,
expected: []map[string]string{},
expectedError: errors.New("duck.mallard.io \"quak\" not found"),
expectedError: fmt.Errorf("duck.mallard.io \"quak\" not found"),
},
***/
{
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestGenerateParamsForDuckType(t *testing.T) {
resource: duckType,
values: nil,
expected: nil,
expectedError: errors.New("There is a problem with the definition of the ClusterDecisionResource generator"),
expectedError: fmt.Errorf("There is a problem with the definition of the ClusterDecisionResource generator"),
},
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/generators/interface.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package generators

import (
"errors"
"fmt"
"time"

argoprojiov1alpha1 "github.com/argoproj/applicationset/api/v1alpha1"
Expand All @@ -23,7 +23,7 @@ type Generator interface {
GetTemplate(appSetGenerator *argoprojiov1alpha1.ApplicationSetGenerator) *argoprojiov1alpha1.ApplicationSetTemplate
}

var EmptyAppSetGeneratorError = errors.New("ApplicationSet is empty")
var EmptyAppSetGeneratorError = fmt.Errorf("ApplicationSet is empty")
var NoRequeueAfter time.Duration

// DefaultRequeueAfterSeconds is used when GetRequeueAfter is not specified, it is the default time to wait before the next reconcile loop
Expand Down
7 changes: 3 additions & 4 deletions pkg/generators/matrix.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package generators

import (
"errors"
"fmt"
"time"

Expand All @@ -12,9 +11,9 @@ import (
var _ Generator = (*MatrixGenerator)(nil)

var (
ErrMoreThanTwoGenerators = errors.New("found more than two generators, Matrix support only two")
ErrLessThanTwoGenerators = errors.New("found less than two generators, Matrix support only two")
ErrMoreThenOneInnerGenerators = errors.New("found more than one generator in matrix.Generators")
ErrMoreThanTwoGenerators = fmt.Errorf("found more than two generators, Matrix support only two")
ErrLessThanTwoGenerators = fmt.Errorf("found less than two generators, Matrix support only two")
ErrMoreThenOneInnerGenerators = fmt.Errorf("found more than one generator in matrix.Generators")
)

type MatrixGenerator struct {
Expand Down
7 changes: 3 additions & 4 deletions pkg/generators/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package generators

import (
"encoding/json"
"errors"
"fmt"
"time"

Expand All @@ -13,9 +12,9 @@ import (
var _ Generator = (*MergeGenerator)(nil)

var (
ErrLessThanTwoGeneratorsInMerge = errors.New("found less than two generators, Merge requires two or more")
ErrNoMergeKeys = errors.New("no merge keys were specified, Merge requires at least one")
ErrNonUniqueParamSets = errors.New("the parameters from a generator were not unique by the given mergeKeys, Merge requires all param sets to be unique")
ErrLessThanTwoGeneratorsInMerge = fmt.Errorf("found less than two generators, Merge requires two or more")
ErrNoMergeKeys = fmt.Errorf("no merge keys were specified, Merge requires at least one")
ErrNonUniqueParamSets = fmt.Errorf("the parameters from a generator were not unique by the given mergeKeys, Merge requires all param sets to be unique")
)

type MergeGenerator struct {
Expand Down
6 changes: 3 additions & 3 deletions pkg/generators/pull_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package generators

import (
"context"
"errors"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -49,11 +49,11 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
return pullrequest.NewFakeService(
ctx,
nil,
errors.New("fake error"),
fmt.Errorf("fake error"),
)
},
expected: nil,
expectedErr: errors.New("error listing repos: fake error"),
expectedErr: fmt.Errorf("error listing repos: fake error"),
},
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/services/repo_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package services

import (
"context"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/util/db"
"github.com/argoproj/argo-cd/v2/util/git"
"github.com/pkg/errors"
)

// RepositoryDB Is a lean facade for ArgoDB,
Expand Down Expand Up @@ -41,7 +41,7 @@ func NewArgoCDService(db db.ArgoDB, repoServerAddress string) Repos {
func (a *argoCDService) GetFiles(ctx context.Context, repoURL string, revision string, pattern string) (map[string][]byte, error) {
repo, err := a.repositoriesDB.GetRepository(ctx, repoURL)
if err != nil {
return nil, errors.Wrap(err, "Error in GetRepository")
return nil, fmt.Errorf("Error in GetRepository: %w", err)
}

gitRepoClient, err := git.NewClient(repo.Repo, repo.GetGitCreds(), repo.IsInsecure(), repo.IsLFSEnabled(), repo.Proxy)
Expand All @@ -57,7 +57,7 @@ func (a *argoCDService) GetFiles(ctx context.Context, repoURL string, revision s

paths, err := gitRepoClient.LsFiles(pattern)
if err != nil {
return nil, errors.Wrap(err, "Error during listing files of local repo")
return nil, fmt.Errorf("Error during listing files of local repo: %w", err)
}

res := map[string][]byte{}
Expand All @@ -76,7 +76,7 @@ func (a *argoCDService) GetDirectories(ctx context.Context, repoURL string, revi

repo, err := a.repositoriesDB.GetRepository(ctx, repoURL)
if err != nil {
return nil, errors.Wrap(err, "Error in GetRepository")
return nil, fmt.Errorf("Error in GetRepository: %w", err)
}

gitRepoClient, err := git.NewClient(repo.Repo, repo.GetGitCreds(), repo.IsInsecure(), repo.IsLFSEnabled(), repo.Proxy)
Expand Down Expand Up @@ -129,21 +129,21 @@ func (a *argoCDService) GetDirectories(ctx context.Context, repoURL string, revi
func checkoutRepo(gitRepoClient git.Client, revision string) error {
err := gitRepoClient.Init()
if err != nil {
return errors.Wrap(err, "Error during initializing repo")
return fmt.Errorf("Error during initializing repo: %w", err)
}

err = gitRepoClient.Fetch(revision)
if err != nil {
return errors.Wrap(err, "Error during fetching repo")
return fmt.Errorf("Error during fetching repo: %w", err)
}

commitSHA, err := gitRepoClient.LsRemote(revision)
if err != nil {
return errors.Wrap(err, "Error during fetching commitSHA")
return fmt.Errorf("Error during fetching commitSHA: %w", err)
}
err = gitRepoClient.Checkout(commitSHA)
if err != nil {
return errors.Wrap(err, "Error during repo checkout")
return fmt.Errorf("Error during repo checkout: %w", err)
}
return nil
}
8 changes: 4 additions & 4 deletions pkg/services/repo_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package services

import (
"context"
"errors"
"fmt"
"sort"
"testing"

Expand Down Expand Up @@ -60,9 +60,9 @@ func TestGetDirectories(t *testing.T) {
repoRes: &v1alpha1.Repository{
Repo: "https://github.com/argoproj/argocd-example-apps/",
},
repoErr: errors.New("Simulated error from GetRepository"),
repoErr: fmt.Errorf("Simulated error from GetRepository"),
expected: nil,
expectedError: errors.New("Error in GetRepository: Simulated error from GetRepository"),
expectedError: fmt.Errorf("Error in GetRepository: Simulated error from GetRepository"),
},
{
name: "Test against repository containing no directories",
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestGetFiles(t *testing.T) {
revision: "this-tag-does-not-exist",
pattern: "*",
expectSubsetOfPaths: []string{},
expectedError: errors.New("Error during fetching repo: `git fetch origin this-tag-does-not-exist --tags --force` failed exit status 128: fatal: couldn't find remote ref this-tag-does-not-exist"),
expectedError: fmt.Errorf("Error during fetching repo: `git fetch origin this-tag-does-not-exist --tags --force` failed exit status 128: fatal: couldn't find remote ref this-tag-does-not-exist"),
},
{
name: "pull a specific revision of example apps, and use a ** pattern",
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/clusterUtils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package utils

import (
"context"
"errors"
"fmt"
"testing"

"github.com/argoproj/applicationset/test/e2e/fixture/applicationsets/utils"
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestValidateDestination(t *testing.T) {
kubeclientset := fake.NewSimpleClientset()

kubeclientset.PrependReactor("list", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) {
return true, nil, errors.New("an error occurred")
return true, nil, fmt.Errorf("an error occurred")
})

err := ValidateDestination(context.Background(), &dest, kubeclientset, utils.ArgoCDNamespace)
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/map_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package utils

import (
"errors"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -27,7 +27,7 @@ func TestCombineStringMaps(t *testing.T) {
left: map[string]string{"foo": "bar", "a": "fail"},
right: map[string]string{"a": "b", "c": "d"},
expected: map[string]string{"a": "b", "foo": "bar"},
expectedErr: errors.New("found duplicate key a with different value, a: fail ,b: b"),
expectedErr: fmt.Errorf("found duplicate key a with different value, a: fail ,b: b"),
},
{
name: "pass if keys & values are the same",
Expand Down
3 changes: 1 addition & 2 deletions pkg/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

argoprojiov1alpha1 "github.com/argoproj/applicationset/api/v1alpha1"
argov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/valyala/fasttemplate"
)
Expand Down Expand Up @@ -78,7 +77,7 @@ func (r *Render) replace(fstTmpl *fasttemplate.Template, replaceMap map[string]s
// just write the same string back
return w.Write([]byte(fmt.Sprintf("{{%s}}", tag)))
}
unresolvedErr = errors.Errorf("failed to resolve {{%s}}", tag)
unresolvedErr = fmt.Errorf("failed to resolve {{%s}}", tag)
return 0, nil
}
// The following escapes any special characters (e.g. newlines, tabs, etc...)
Expand Down