Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Less error prone errors in actor invokation interface. #59

Closed
Kubuxu opened this issue Jul 18, 2019 · 5 comments · Fixed by #66
Closed

Less error prone errors in actor invokation interface. #59

Kubuxu opened this issue Jul 18, 2019 · 5 comments · Fixed by #66
Assignees

Comments

@Kubuxu
Copy link
Contributor

Kubuxu commented Jul 18, 2019

Currently inokation interface is:

Send(to address.Address, method uint64, value types.BigInt, params []byte) ([]byte, uint8, error)

It is hard to differentiate which errors should be reported as errors and which should be return codes.

There are two ideas I have, either we change the interface to:

Send(...) ([]byte, actorError)
type aError struct {
   msg string
   err error
   frame xerrors.Frame
   retCode uint8
   fatal bool
}
type actorError *aError

func NewFatalErr(msg string, err error) actorError {...}
fund NewRetErr(msg string, code uint8, err error) actorError {...}

// Fatal marks an error that should abort execution of message
func (actorError) IsFatal() bool {
   return actorError.fatal
}
func (actorError) RetCode() uint8 {
   return actorError.retCode
}
func IsFatal(err actorError) bool {
    return err != nil && err.IsFatal()
}
func RetCode(err actorError) uint8 {
    if err == nil {
        return 0
    } else { return err.RetCode() }
}

And create wrappers around all apis to return actorError.
Then handling of api call would be:

// If we want to recover
result, err := vmctx.Something()
if IsFatal(err) {
  return nil, err // or: nil, Wrap(err, "optional msg")
}
if RetCode(err) != 0 {
  // Recover
}

// If we don't want to try to recover
// If we want to recover
result, err := vmctx.Something()
if err != nil {
  return nil, err// or: nil, Wrap(err, "optional msg")
}
@Kubuxu Kubuxu changed the title Less error prone actor invokation interface. Less error prone errors in actor invokation interface. Jul 18, 2019
@Kubuxu
Copy link
Contributor Author

Kubuxu commented Jul 18, 2019

Another option would be to use xerrors facilities to convey additional information in wrapped errors.

Then we would keep the []byte, error in the interface but Send and Invoke would be checking if wrapping is correct. As in, one error in the Unwrap chain has to fulfil: interface{ IsFatal() bool } or interface{ RetCode() uint8 }.

I think this option is better (it means we don't have to write our own facilities for wrapping errors in additional messages but we also shoudl firewall/wrap all APIs.

@Kubuxu
Copy link
Contributor Author

Kubuxu commented Jul 18, 2019

In case of actor code calling API, both of those ways would look the same.
Internals change significantly.
They also both require as to wrap all APIs which would mark errors in a special way.

@Kubuxu
Copy link
Contributor Author

Kubuxu commented Jul 18, 2019

I will probably try to prototype something with xerrors/Go1.13 errors tomorrow.

@whyrusleeping
Copy link
Member

I think i like the actorError type idea the most. It means we can't ever accidentally return an incorrect error. using the type system to enforce some more correctness

@Kubuxu Kubuxu self-assigned this Jul 18, 2019
@Kubuxu
Copy link
Contributor Author

Kubuxu commented Jul 18, 2019

It makes sense to use explicit type as this is a cohesive system.
I will probably make functions that accept error and transform it to actorError a bit unpleasant to use so we are well motivated to create wrappers on APIs where we can precisely analyse errors one, instead of transforming error to actorError ad-hoc.

magik6k added a commit that referenced this issue Aug 10, 2020
ffiwrapper: Insert alignment between pieces
magik6k pushed a commit that referenced this issue Aug 10, 2020
…-func

Separate precommit deposit estimation func
dumikau pushed a commit to protofire/lotus that referenced this issue Jun 8, 2023
* Remove boilerplate from mir_test

* fix ctrl-c in tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants