Skip to content

Commit

Permalink
Recoverable struct field must be exported
Browse files Browse the repository at this point in the history
  • Loading branch information
schmichael committed Mar 28, 2017
1 parent 6a4e1d1 commit ae9d495
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion client/driver/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func TestDockerDriver_Start_BadPull_Recoverable(t *testing.T) {

if rerr, ok := err.(*structs.RecoverableError); !ok {
t.Fatalf("want recoverable error: %+v", err)
} else if !rerr.Recoverable() {
} else if !rerr.IsRecoverable() {
t.Fatalf("error not recoverable: %+v", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/getter/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ func (g *GetError) Error() string {
return g.Err.Error()
}

func (g *GetError) Recoverable() bool {
func (g *GetError) IsRecoverable() bool {
return g.recoverable
}
2 changes: 1 addition & 1 deletion nomad/node_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2030,7 +2030,7 @@ func TestClientEndpoint_DeriveVaultToken_VaultError(t *testing.T) {
if err != nil {
t.Fatalf("bad: %v", err)
}
if resp.Error == nil || !resp.Error.Recoverable() {
if resp.Error == nil || !resp.Error.IsRecoverable() {
t.Fatalf("bad: %+v", resp.Error)
}
}
14 changes: 7 additions & 7 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4177,7 +4177,7 @@ type KeyringRequest struct {
// be retried or it is fatal.
type RecoverableError struct {
Err string
recoverable bool
Recoverable bool
}

// NewRecoverableError is used to wrap an error and mark it as recoverable or
Expand All @@ -4189,37 +4189,37 @@ func NewRecoverableError(e error, recoverable bool) error {

return &RecoverableError{
Err: e.Error(),
recoverable: recoverable,
Recoverable: recoverable,
}
}

// WrapRecoverable wraps an existing error in a new RecoverableError with a new
// message. If the error was recoverable before the returned error is as well;
// otherwise it is unrecoverable.
func WrapRecoverable(msg string, err error) error {
return &RecoverableError{Err: msg, recoverable: IsRecoverable(err)}
return &RecoverableError{Err: msg, Recoverable: IsRecoverable(err)}
}

func (r *RecoverableError) Error() string {
return r.Err
}

func (r *RecoverableError) Recoverable() bool {
return r.recoverable
func (r *RecoverableError) IsRecoverable() bool {
return r.Recoverable
}

// Recoverable is an interface for errors to implement to indicate whether or
// not they are fatal or recoverable.
type Recoverable interface {
error
Recoverable() bool
IsRecoverable() bool
}

// IsRecoverable returns true if error is a RecoverableError with
// Recoverable=true. Otherwise false is returned.
func IsRecoverable(e error) bool {
if re, ok := e.(Recoverable); ok {
return re.Recoverable()
return re.IsRecoverable()
}
return false
}
2 changes: 1 addition & 1 deletion nomad/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ func TestVaultClient_CreateToken_Prestart(t *testing.T) {

if rerr, ok := err.(*structs.RecoverableError); !ok {
t.Fatalf("Err should have been type recoverable error")
} else if ok && !rerr.Recoverable() {
} else if ok && !rerr.IsRecoverable() {
t.Fatalf("Err should have been recoverable")
}
}
Expand Down

0 comments on commit ae9d495

Please sign in to comment.