diff --git a/chain/actors/aerrors/wrap.go b/chain/actors/aerrors/wrap.go index 9b5e528c1..da15cf233 100644 --- a/chain/actors/aerrors/wrap.go +++ b/chain/actors/aerrors/wrap.go @@ -27,6 +27,26 @@ func New(retCode uint8, message string) ActorError { } } +// Newf creates a new non-fatal error +func Newf(retCode uint8, format string, args ...interface{}) ActorError { + if retCode == 0 { + return &actorError{ + fatal: true, + retCode: 0, + + msg: "tried creating an error and setting RetCode to 0", + frame: xerrors.Caller(1), + err: fmt.Errorf(format, args...), + } + } + return &actorError{ + retCode: retCode, + + msg: fmt.Sprintf(format, args...), + frame: xerrors.Caller(1), + } +} + // Wrap extens chain of errors with a message func Wrap(err ActorError, message string) ActorError { if err == nil { diff --git a/chain/invoker.go b/chain/invoker.go index 5cd32c3ec..0d8884d92 100644 --- a/chain/invoker.go +++ b/chain/invoker.go @@ -35,10 +35,10 @@ func (inv *invoker) Invoke(act *types.Actor, vmctx *VMContext, method uint64, pa code, ok := inv.builtInCode[act.Code] if !ok { - return nil, aerrors.Escalate(fmt.Errorf("no code for actor %s", act.Code), "") + return nil, aerrors.Newf(255, "no code for actor %s", act.Code) } if method >= uint64(len(code)) || code[method] == nil { - return nil, aerrors.Escalate(fmt.Errorf("no method %d on actor", method), "") + return nil, aerrors.Newf(255, "no method %d on actor", method) } return code[method](act, vmctx, params)