refactor: renames
This commit is contained in:
parent
f3cae55bd4
commit
b755ce9528
@ -77,7 +77,7 @@ func (a Actor) Exports() []interface{} {
|
||||
MethodDeleteActor: a.DeleteActor,
|
||||
MethodSend: a.Send,
|
||||
MethodMutateState: a.MutateState,
|
||||
MethodAbort: a.Abort,
|
||||
MethodAbort: a.AbortWith,
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,17 +235,17 @@ func (a Actor) MutateState(rt runtime.Runtime, args *MutateStateArgs) *adt.Empty
|
||||
return nil
|
||||
}
|
||||
|
||||
// AbortArgs are the arguments to the abort method, specifying the exit code to
|
||||
// (optionally) abort with and the message.
|
||||
type AbortArgs struct {
|
||||
// AbortWithArgs are the arguments to the Actor.AbortWith method, specifying the
|
||||
// exit code to (optionally) abort with and the message.
|
||||
type AbortWithArgs struct {
|
||||
Code exitcode.ExitCode
|
||||
NoCode bool
|
||||
Message string
|
||||
Uncontrolled bool
|
||||
}
|
||||
|
||||
// Abort simply causes a panic or abort with the passed exit code.
|
||||
func (a Actor) Abort(rt runtime.Runtime, args *AbortArgs) *adt.EmptyValue {
|
||||
if args.NoCode { // no code, just plain old panic
|
||||
// AbortWith simply causes a panic with the passed exit code.
|
||||
func (a Actor) AbortWith(rt runtime.Runtime, args *AbortWithArgs) *adt.EmptyValue {
|
||||
if args.Uncontrolled { // uncontrolled abort: directly panic
|
||||
panic(args.Message)
|
||||
} else {
|
||||
rt.Abortf(args.Code, args.Message)
|
||||
|
@ -615,14 +615,14 @@ func (t *MutateStateArgs) UnmarshalCBOR(r io.Reader) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var lengthBufAbortArgs = []byte{131}
|
||||
var lengthBufAbortWithArgs = []byte{131}
|
||||
|
||||
func (t *AbortArgs) MarshalCBOR(w io.Writer) error {
|
||||
func (t *AbortWithArgs) MarshalCBOR(w io.Writer) error {
|
||||
if t == nil {
|
||||
_, err := w.Write(cbg.CborNull)
|
||||
return err
|
||||
}
|
||||
if _, err := w.Write(lengthBufAbortArgs); err != nil {
|
||||
if _, err := w.Write(lengthBufAbortWithArgs); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -639,11 +639,6 @@ func (t *AbortArgs) MarshalCBOR(w io.Writer) error {
|
||||
}
|
||||
}
|
||||
|
||||
// t.NoCode (bool) (bool)
|
||||
if err := cbg.WriteBool(w, t.NoCode); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// t.Message (string) (string)
|
||||
if len(t.Message) > cbg.MaxLength {
|
||||
return xerrors.Errorf("Value in field t.Message was too long")
|
||||
@ -655,11 +650,16 @@ func (t *AbortArgs) MarshalCBOR(w io.Writer) error {
|
||||
if _, err := io.WriteString(w, string(t.Message)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// t.Uncontrolled (bool) (bool)
|
||||
if err := cbg.WriteBool(w, t.Uncontrolled); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *AbortArgs) UnmarshalCBOR(r io.Reader) error {
|
||||
*t = AbortArgs{}
|
||||
func (t *AbortWithArgs) UnmarshalCBOR(r io.Reader) error {
|
||||
*t = AbortWithArgs{}
|
||||
|
||||
br := cbg.GetPeeker(r)
|
||||
scratch := make([]byte, 8)
|
||||
@ -701,23 +701,6 @@ func (t *AbortArgs) UnmarshalCBOR(r io.Reader) error {
|
||||
|
||||
t.Code = exitcode.ExitCode(extraI)
|
||||
}
|
||||
// t.NoCode (bool) (bool)
|
||||
|
||||
maj, extra, err = cbg.CborReadHeaderBuf(br, scratch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if maj != cbg.MajOther {
|
||||
return fmt.Errorf("booleans must be major type 7")
|
||||
}
|
||||
switch extra {
|
||||
case 20:
|
||||
t.NoCode = false
|
||||
case 21:
|
||||
t.NoCode = true
|
||||
default:
|
||||
return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra)
|
||||
}
|
||||
// t.Message (string) (string)
|
||||
|
||||
{
|
||||
@ -728,5 +711,22 @@ func (t *AbortArgs) UnmarshalCBOR(r io.Reader) error {
|
||||
|
||||
t.Message = string(sval)
|
||||
}
|
||||
// t.Uncontrolled (bool) (bool)
|
||||
|
||||
maj, extra, err = cbg.CborReadHeaderBuf(br, scratch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if maj != cbg.MajOther {
|
||||
return fmt.Errorf("booleans must be major type 7")
|
||||
}
|
||||
switch extra {
|
||||
case 20:
|
||||
t.Uncontrolled = false
|
||||
case 21:
|
||||
t.Uncontrolled = true
|
||||
default:
|
||||
return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ func main() {
|
||||
chaos.SendArgs{},
|
||||
chaos.SendReturn{},
|
||||
chaos.MutateStateArgs{},
|
||||
chaos.AbortArgs{},
|
||||
chaos.AbortWithArgs{},
|
||||
); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user