Make invoker error non fatal

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
Jakub Sztandera 2019-07-23 20:15:16 +02:00
parent 681f40ad75
commit 68cfff17e5
2 changed files with 22 additions and 2 deletions

View File

@ -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 {

View File

@ -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)