Preventing panics of RecoverableError casts

This commit is contained in:
Brad Sickles 2017-02-01 14:38:59 -05:00
parent d470fe494d
commit 429fdb3ce7
2 changed files with 3 additions and 3 deletions

View file

@ -944,7 +944,7 @@ func (n *Node) DeriveVaultToken(args *structs.DeriveVaultTokenRequest,
// setErr is a helper for setting the recoverable error on the reply and
// logging it
setErr := func(e error, recoverable bool) {
reply.Error = structs.NewRecoverableError(e, recoverable).(*structs.RecoverableError)
reply.Error = structs.NewRecoverableError(e, recoverable)
n.srv.logger.Printf("[ERR] nomad.client: DeriveVaultToken failed (recoverable %v): %v", recoverable, e)
}
@ -1134,7 +1134,7 @@ func (n *Node) DeriveVaultToken(args *structs.DeriveVaultTokenRequest,
if rerr, ok := createErr.(*structs.RecoverableError); ok {
reply.Error = rerr
} else {
reply.Error = structs.NewRecoverableError(createErr, false).(*structs.RecoverableError)
reply.Error = structs.NewRecoverableError(createErr, false)
}
return nil

View file

@ -4054,7 +4054,7 @@ type RecoverableError struct {
// NewRecoverableError is used to wrap an error and mark it as recoverable or
// not.
func NewRecoverableError(e error, recoverable bool) error {
func NewRecoverableError(e error, recoverable bool) *RecoverableError {
if e == nil {
return nil
}