Skip to content

Commit d232d3d

Browse files
authored
Standardize error handling (#680)
1 parent 9cbbec4 commit d232d3d

File tree

225 files changed

+1340
-1509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

225 files changed

+1340
-1509
lines changed

pkg/apis/backup/v1/backup_policy_validate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
package v1
2424

2525
import (
26-
"fmt"
2726
"time"
2827

28+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
2929
"github.com/robfig/cron"
3030
)
3131

@@ -39,9 +39,9 @@ func (a *ArangoBackupPolicy) Validate() error {
3939

4040
func (a *ArangoBackupPolicySpec) Validate() error {
4141
if expr, err := cron.ParseStandard(a.Schedule); err != nil {
42-
return fmt.Errorf("error while parsing expr: %s", err.Error())
42+
return errors.Newf("error while parsing expr: %s", err.Error())
4343
} else if expr.Next(time.Now()).IsZero() {
44-
return fmt.Errorf("invalid schedule format")
44+
return errors.Newf("invalid schedule format")
4545
}
4646

4747
return nil

pkg/apis/backup/v1/backup_validate.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
package v1
2424

25-
import "fmt"
25+
import "github.com/arangodb/kube-arangodb/pkg/util/errors"
2626

2727
func (a *ArangoBackup) Validate() error {
2828
if err := a.Spec.Validate(); err != nil {
@@ -38,7 +38,7 @@ func (a *ArangoBackup) Validate() error {
3838

3939
func (a *ArangoBackupSpec) Validate() error {
4040
if a.Deployment.Name == "" {
41-
return fmt.Errorf("deployment name can not be empty")
41+
return errors.Newf("deployment name can not be empty")
4242
}
4343

4444
if a.Download != nil {
@@ -58,15 +58,15 @@ func (a *ArangoBackupSpec) Validate() error {
5858

5959
func (a *ArangoBackupSpecOperation) Validate() error {
6060
if a.RepositoryURL == "" {
61-
return fmt.Errorf("RepositoryURL can not be empty")
61+
return errors.Newf("RepositoryURL can not be empty")
6262
}
6363

6464
return nil
6565
}
6666

6767
func (a *ArangoBackupSpecDownload) Validate() error {
6868
if a.ID == "" {
69-
return fmt.Errorf("ID can not be empty")
69+
return errors.Newf("ID can not be empty")
7070
}
7171

7272
return a.ArangoBackupSpecOperation.Validate()

pkg/apis/deployment/v1/authentication_spec.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
package v1
2424

2525
import (
26-
"github.com/pkg/errors"
27-
2826
"github.com/arangodb/kube-arangodb/pkg/util"
27+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
2928
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
3029
)
3130

@@ -53,11 +52,11 @@ func (s AuthenticationSpec) IsAuthenticated() bool {
5352
// Validate the given spec
5453
func (s AuthenticationSpec) Validate(required bool) error {
5554
if required && !s.IsAuthenticated() {
56-
return maskAny(errors.Wrap(ValidationError, "JWT secret is required"))
55+
return errors.WithStack(errors.Wrap(ValidationError, "JWT secret is required"))
5756
}
5857
if s.IsAuthenticated() {
5958
if err := k8sutil.ValidateResourceName(s.GetJWTSecretName()); err != nil {
60-
return maskAny(err)
59+
return errors.WithStack(err)
6160
}
6261
}
6362
return nil

pkg/apis/deployment/v1/bootstrap.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
package v1
2222

2323
import (
24-
"fmt"
24+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
2525

2626
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
2727
)
@@ -84,16 +84,16 @@ func (b *BootstrapSpec) Validate() error {
8484
for username, secretname := range b.PasswordSecretNames {
8585
// Remove this restriction as soon as we can bootstrap databases
8686
if username != UserNameRoot {
87-
return fmt.Errorf("only username `root` allowed in passwordSecretNames")
87+
return errors.Newf("only username `root` allowed in passwordSecretNames")
8888
}
8989

9090
if secretname.IsNone() {
9191
if username != UserNameRoot {
92-
return fmt.Errorf("magic value None not allowed for %s", username)
92+
return errors.Newf("magic value None not allowed for %s", username)
9393
}
9494
} else {
9595
if err := k8sutil.ValidateResourceName(string(secretname)); err != nil {
96-
return maskAny(err)
96+
return errors.WithStack(err)
9797
}
9898
}
9999
}

pkg/apis/deployment/v1/chaos_spec.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ package v1
2525
import (
2626
time "time"
2727

28+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
29+
2830
"github.com/arangodb/kube-arangodb/pkg/util"
29-
"github.com/pkg/errors"
3031
)
3132

3233
// ChaosSpec holds configuration for the deployment chaos monkey.
@@ -58,10 +59,10 @@ func (s ChaosSpec) GetKillPodProbability() Percent {
5859
func (s ChaosSpec) Validate() error {
5960
if s.IsEnabled() {
6061
if s.GetInterval() <= 0 {
61-
return maskAny(errors.Wrapf(ValidationError, "Interval must be > 0"))
62+
return errors.WithStack(errors.Wrapf(ValidationError, "Interval must be > 0"))
6263
}
6364
if err := s.GetKillPodProbability().Validate(); err != nil {
64-
return maskAny(err)
65+
return errors.WithStack(err)
6566
}
6667
}
6768
return nil

pkg/apis/deployment/v1/deployment.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package v1
2424

2525
import (
2626
"github.com/arangodb/kube-arangodb/pkg/apis/deployment"
27+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
2728
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
2829
)
2930

@@ -74,22 +75,22 @@ func (d *ArangoDeployment) ForeachServerGroup(cb ServerGroupFunc, status *Deploy
7475
status = &d.Status
7576
}
7677
if err := cb(ServerGroupAgents, d.Spec.Agents, &status.Members.Agents); err != nil {
77-
return maskAny(err)
78+
return errors.WithStack(err)
7879
}
7980
if err := cb(ServerGroupSingle, d.Spec.Single, &status.Members.Single); err != nil {
80-
return maskAny(err)
81+
return errors.WithStack(err)
8182
}
8283
if err := cb(ServerGroupDBServers, d.Spec.DBServers, &status.Members.DBServers); err != nil {
83-
return maskAny(err)
84+
return errors.WithStack(err)
8485
}
8586
if err := cb(ServerGroupCoordinators, d.Spec.Coordinators, &status.Members.Coordinators); err != nil {
86-
return maskAny(err)
87+
return errors.WithStack(err)
8788
}
8889
if err := cb(ServerGroupSyncMasters, d.Spec.SyncMasters, &status.Members.SyncMasters); err != nil {
89-
return maskAny(err)
90+
return errors.WithStack(err)
9091
}
9192
if err := cb(ServerGroupSyncWorkers, d.Spec.SyncWorkers, &status.Members.SyncWorkers); err != nil {
92-
return maskAny(err)
93+
return errors.WithStack(err)
9394
}
9495
return nil
9596
}

pkg/apis/deployment/v1/deployment_mode.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
package v1
2424

2525
import (
26-
"github.com/pkg/errors"
26+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
2727
)
2828

2929
// DeploymentMode specifies the type of ArangoDB deployment to create.
@@ -45,7 +45,7 @@ func (m DeploymentMode) Validate() error {
4545
case DeploymentModeSingle, DeploymentModeActiveFailover, DeploymentModeCluster:
4646
return nil
4747
default:
48-
return maskAny(errors.Wrapf(ValidationError, "Unknown deployment mode: '%s'", string(m)))
48+
return errors.WithStack(errors.Wrapf(ValidationError, "Unknown deployment mode: '%s'", string(m)))
4949
}
5050
}
5151

pkg/apis/deployment/v1/deployment_spec.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ import (
2828
"fmt"
2929
"reflect"
3030

31+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
32+
3133
"github.com/arangodb/kube-arangodb/pkg/util"
32-
"github.com/pkg/errors"
34+
3335
core "k8s.io/api/core/v1"
3436
)
3537

@@ -44,7 +46,7 @@ func validatePullPolicy(v core.PullPolicy) error {
4446
case "", core.PullAlways, core.PullNever, core.PullIfNotPresent:
4547
return nil
4648
default:
47-
return maskAny(errors.Wrapf(ValidationError, "Unknown pull policy: '%s'", string(v)))
49+
return errors.WithStack(errors.Wrapf(ValidationError, "Unknown pull policy: '%s'", string(v)))
4850
}
4951
}
5052

@@ -328,64 +330,64 @@ func (s *DeploymentSpec) SetDefaultsFrom(source DeploymentSpec) {
328330
// Return errors when validation fails, nil on success.
329331
func (s *DeploymentSpec) Validate() error {
330332
if err := s.GetMode().Validate(); err != nil {
331-
return maskAny(errors.Wrap(err, "spec.mode"))
333+
return errors.WithStack(errors.Wrap(err, "spec.mode"))
332334
}
333335
if err := s.GetEnvironment().Validate(); err != nil {
334-
return maskAny(errors.Wrap(err, "spec.environment"))
336+
return errors.WithStack(errors.Wrap(err, "spec.environment"))
335337
}
336338
if err := s.GetStorageEngine().Validate(); err != nil {
337-
return maskAny(errors.Wrap(err, "spec.storageEngine"))
339+
return errors.WithStack(errors.Wrap(err, "spec.storageEngine"))
338340
}
339341
if err := validatePullPolicy(s.GetImagePullPolicy()); err != nil {
340-
return maskAny(errors.Wrap(err, "spec.imagePullPolicy"))
342+
return errors.WithStack(errors.Wrap(err, "spec.imagePullPolicy"))
341343
}
342344
if s.GetImage() == "" {
343-
return maskAny(errors.Wrapf(ValidationError, "spec.image must be set"))
345+
return errors.WithStack(errors.Wrapf(ValidationError, "spec.image must be set"))
344346
}
345347
if err := s.ExternalAccess.Validate(); err != nil {
346-
return maskAny(errors.Wrap(err, "spec.externalAccess"))
348+
return errors.WithStack(errors.Wrap(err, "spec.externalAccess"))
347349
}
348350
if err := s.RocksDB.Validate(); err != nil {
349-
return maskAny(errors.Wrap(err, "spec.rocksdb"))
351+
return errors.WithStack(errors.Wrap(err, "spec.rocksdb"))
350352
}
351353
if err := s.Authentication.Validate(false); err != nil {
352-
return maskAny(errors.Wrap(err, "spec.auth"))
354+
return errors.WithStack(errors.Wrap(err, "spec.auth"))
353355
}
354356
if err := s.TLS.Validate(); err != nil {
355-
return maskAny(errors.Wrap(err, "spec.tls"))
357+
return errors.WithStack(errors.Wrap(err, "spec.tls"))
356358
}
357359
if err := s.Sync.Validate(s.GetMode()); err != nil {
358-
return maskAny(errors.Wrap(err, "spec.sync"))
360+
return errors.WithStack(errors.Wrap(err, "spec.sync"))
359361
}
360362
if err := s.Single.Validate(ServerGroupSingle, s.GetMode().HasSingleServers(), s.GetMode(), s.GetEnvironment()); err != nil {
361-
return maskAny(err)
363+
return errors.WithStack(err)
362364
}
363365
if err := s.Agents.Validate(ServerGroupAgents, s.GetMode().HasAgents(), s.GetMode(), s.GetEnvironment()); err != nil {
364-
return maskAny(err)
366+
return errors.WithStack(err)
365367
}
366368
if err := s.DBServers.Validate(ServerGroupDBServers, s.GetMode().HasDBServers(), s.GetMode(), s.GetEnvironment()); err != nil {
367-
return maskAny(err)
369+
return errors.WithStack(err)
368370
}
369371
if err := s.Coordinators.Validate(ServerGroupCoordinators, s.GetMode().HasCoordinators(), s.GetMode(), s.GetEnvironment()); err != nil {
370-
return maskAny(err)
372+
return errors.WithStack(err)
371373
}
372374
if err := s.SyncMasters.Validate(ServerGroupSyncMasters, s.Sync.IsEnabled(), s.GetMode(), s.GetEnvironment()); err != nil {
373-
return maskAny(err)
375+
return errors.WithStack(err)
374376
}
375377
if err := s.SyncWorkers.Validate(ServerGroupSyncWorkers, s.Sync.IsEnabled(), s.GetMode(), s.GetEnvironment()); err != nil {
376-
return maskAny(err)
378+
return errors.WithStack(err)
377379
}
378380
if err := s.Metrics.Validate(); err != nil {
379-
return maskAny(errors.Wrap(err, "spec.metrics"))
381+
return errors.WithStack(errors.Wrap(err, "spec.metrics"))
380382
}
381383
if err := s.Chaos.Validate(); err != nil {
382-
return maskAny(errors.Wrap(err, "spec.chaos"))
384+
return errors.WithStack(errors.Wrap(err, "spec.chaos"))
383385
}
384386
if err := s.License.Validate(); err != nil {
385-
return maskAny(errors.Wrap(err, "spec.licenseKey"))
387+
return errors.WithStack(errors.Wrap(err, "spec.licenseKey"))
386388
}
387389
if err := s.Bootstrap.Validate(); err != nil {
388-
return maskAny(err)
390+
return errors.WithStack(err)
389391
}
390392
return nil
391393
}

pkg/apis/deployment/v1/deployment_spec_image.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
package v1
2424

25-
import "fmt"
25+
import "github.com/arangodb/kube-arangodb/pkg/util/errors"
2626

2727
type DeploymentImageDiscoveryModeSpec string
2828

@@ -42,7 +42,7 @@ func (d DeploymentImageDiscoveryModeSpec) Validate() error {
4242
case DeploymentImageDiscoveryDirectMode:
4343
return nil
4444
default:
45-
return fmt.Errorf("mode %s is not supported", d)
45+
return errors.Newf("mode %s is not supported", d)
4646
}
4747
}
4848

pkg/apis/deployment/v1/deployment_status_members.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
package v1
2424

2525
import (
26-
"github.com/pkg/errors"
26+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
2727
)
2828

2929
// DeploymentStatusMembers holds the member status of all server groups
@@ -101,27 +101,27 @@ func (ds DeploymentStatusMembers) ForServerGroup(cb func(group ServerGroup, list
101101
switch group {
102102
case ServerGroupSingle:
103103
if err := cb(ServerGroupSingle, ds.Single); err != nil {
104-
return maskAny(err)
104+
return errors.WithStack(err)
105105
}
106106
case ServerGroupAgents:
107107
if err := cb(ServerGroupAgents, ds.Agents); err != nil {
108-
return maskAny(err)
108+
return errors.WithStack(err)
109109
}
110110
case ServerGroupDBServers:
111111
if err := cb(ServerGroupDBServers, ds.DBServers); err != nil {
112-
return maskAny(err)
112+
return errors.WithStack(err)
113113
}
114114
case ServerGroupCoordinators:
115115
if err := cb(ServerGroupCoordinators, ds.Coordinators); err != nil {
116-
return maskAny(err)
116+
return errors.WithStack(err)
117117
}
118118
case ServerGroupSyncMasters:
119119
if err := cb(ServerGroupSyncMasters, ds.SyncMasters); err != nil {
120-
return maskAny(err)
120+
return errors.WithStack(err)
121121
}
122122
case ServerGroupSyncWorkers:
123123
if err := cb(ServerGroupSyncWorkers, ds.SyncWorkers); err != nil {
124-
return maskAny(err)
124+
return errors.WithStack(err)
125125
}
126126
}
127127
return nil
@@ -184,10 +184,10 @@ func (ds *DeploymentStatusMembers) Add(status MemberStatus, group ServerGroup) e
184184
case ServerGroupSyncWorkers:
185185
err = ds.SyncWorkers.add(status)
186186
default:
187-
return maskAny(errors.Wrapf(NotFoundError, "ServerGroup %d is not known", group))
187+
return errors.WithStack(errors.Wrapf(NotFoundError, "ServerGroup %d is not known", group))
188188
}
189189
if err != nil {
190-
return maskAny(err)
190+
return errors.WithStack(err)
191191
}
192192
return nil
193193
}
@@ -209,10 +209,10 @@ func (ds *DeploymentStatusMembers) Update(status MemberStatus, group ServerGroup
209209
case ServerGroupSyncWorkers:
210210
err = ds.SyncWorkers.update(status)
211211
default:
212-
return maskAny(errors.Wrapf(NotFoundError, "ServerGroup %d is not known", group))
212+
return errors.WithStack(errors.Wrapf(NotFoundError, "ServerGroup %d is not known", group))
213213
}
214214
if err != nil {
215-
return maskAny(err)
215+
return errors.WithStack(err)
216216
}
217217
return nil
218218
}
@@ -235,10 +235,10 @@ func (ds *DeploymentStatusMembers) RemoveByID(id string, group ServerGroup) erro
235235
case ServerGroupSyncWorkers:
236236
err = ds.SyncWorkers.removeByID(id)
237237
default:
238-
return maskAny(errors.Wrapf(NotFoundError, "ServerGroup %d is not known", group))
238+
return errors.WithStack(errors.Wrapf(NotFoundError, "ServerGroup %d is not known", group))
239239
}
240240
if err != nil {
241-
return maskAny(err)
241+
return errors.WithStack(err)
242242
}
243243
return nil
244244
}

0 commit comments

Comments
 (0)