From 6cc27b88ac28d1da384b2663435fe4112933ea11 Mon Sep 17 00:00:00 2001 From: scottafk Date: Thu, 6 Jan 2022 11:36:13 +0800 Subject: [PATCH] fix proto and recover err info --- packages/pb/vm.proto | 2 +- packages/script/runtime.go | 75 ++++++++++++++++++++------------------ packages/script/vm.pb.go | 46 +++++++++++------------ 3 files changed, 63 insertions(+), 60 deletions(-) diff --git a/packages/pb/vm.proto b/packages/pb/vm.proto index f87c6bd6..e576b2e4 100644 --- a/packages/pb/vm.proto +++ b/packages/pb/vm.proto @@ -13,7 +13,7 @@ enum VMType { // VMType_CLB is clb vm type CLB = 2; // VMType_CLBMaster is CLBMaster type - CLBMaster = 33; + CLBMaster = 3; } // ObjectType Types of the compiled objects diff --git a/packages/script/runtime.go b/packages/script/runtime.go index 6e0db3c9..26bf4678 100644 --- a/packages/script/runtime.go +++ b/packages/script/runtime.go @@ -554,6 +554,45 @@ func isSelfAssignment(dest, value interface{}) bool { // RunCode executes CodeBlock func (rt *RunTime) RunCode(block *CodeBlock) (status int, err error) { + var cmd *ByteCode + defer func() { + if r := recover(); r != nil { + err = errors.New(r.(string)) + } + if err != nil && !strings.HasPrefix(err.Error(), `{`) { + var curContract, line string + if block.isParentContract() { + stack := block.Parent.Info.(*ContractInfo) + curContract = stack.Name + } + if stack, ok := (*rt.extend)["stack"].([]interface{}); ok { + curContract = stack[len(stack)-1].(string) + } + + line = "]" + if cmd != nil { + line = fmt.Sprintf(":%d]", cmd.Line) + } + + if len(rt.errInfo.Name) > 0 && rt.errInfo.Name != `ExecContract` { + err = fmt.Errorf("%s [%s %s%s", err, rt.errInfo.Name, curContract, line) + rt.errInfo.Name = `` + } else { + out := err.Error() + if strings.HasSuffix(out, `]`) { + prev := strings.LastIndexByte(out, ' ') + if strings.HasPrefix(out[prev+1:], curContract+`:`) { + out = out[:prev+1] + } else { + out = out[:len(out)-1] + ` ` + } + } else { + out += ` [` + } + err = fmt.Errorf(`%s%s%s`, out, curContract, line) + } + } + }() top := make([]interface{}, 8) rt.blocks = append(rt.blocks, &blockStack{Block: block, Offset: len(rt.vars)}) var namemap map[string][]interface{} @@ -600,7 +639,6 @@ func (rt *RunTime) RunCode(block *CodeBlock) (status int, err error) { assign []*VarInfo tmpInt int64 tmpDec decimal.Decimal - cmd *ByteCode ) labels := make([]int, 0) main: @@ -750,7 +788,6 @@ main: rt.cost -= CostCall } err = rt.callFunc(cmd.Cmd, cmd.Value.(*ObjInfo)) - case cmdVar: ivar := cmd.Value.(*VarInfo) var i int @@ -1296,40 +1333,6 @@ main: rt.vm.logger.WithFields(log.Fields{"type": consts.VMError}).Warn("runtime cost limit overflow") err = fmt.Errorf(`runtime cost limit overflow`) } - if err != nil && !strings.HasPrefix(err.Error(), `{`) { - var curContract, line string - if block.isParentContract() { - stack := block.Parent.Info.(*ContractInfo) - curContract = stack.Name - } - if stack, ok := (*rt.extend)["stack"].([]interface{}); ok { - curContract = stack[len(stack)-1].(string) - } - - line = "]" - if cmd != nil { - line = fmt.Sprintf(":%d]", cmd.Line) - } - - if len(rt.errInfo.Name) > 0 && rt.errInfo.Name != `ExecContract` { - err = fmt.Errorf("%s [%s %s%s", err, rt.errInfo.Name, curContract, line) - rt.errInfo.Name = `` - } else { - out := err.Error() - if strings.HasSuffix(out, `]`) { - prev := strings.LastIndexByte(out, ' ') - if strings.HasPrefix(out[prev+1:], curContract+`:`) { - out = out[:prev+1] - } else { - out = out[:len(out)-1] + ` ` - } - } else { - out += ` [` - } - err = fmt.Errorf(`%s%s%s`, out, curContract, line) - } - //rt.vm.logger.WithFields(log.Fields{"type": consts.VMError, "error": err}).Error("error in vm") - } return } diff --git a/packages/script/vm.pb.go b/packages/script/vm.pb.go index 83253a2d..bd428f52 100644 --- a/packages/script/vm.pb.go +++ b/packages/script/vm.pb.go @@ -31,21 +31,21 @@ const ( // VMType_CLB is clb vm type VMType_CLB VMType = 2 // VMType_CLBMaster is CLBMaster type - VMType_CLBMaster VMType = 33 + VMType_CLBMaster VMType = 3 ) var VMType_name = map[int32]string{ - 0: "INVALID", - 1: "Smart", - 2: "CLB", - 33: "CLBMaster", + 0: "INVALID", + 1: "Smart", + 2: "CLB", + 3: "CLBMaster", } var VMType_value = map[string]int32{ "INVALID": 0, "Smart": 1, "CLB": 2, - "CLBMaster": 33, + "CLBMaster": 3, } func (x VMType) String() string { @@ -108,21 +108,21 @@ func init() { func init() { proto.RegisterFile("vm.proto", fileDescriptor_cab246c8c7c5372d) } var fileDescriptor_cab246c8c7c5372d = []byte{ - // 243 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x34, 0x8f, 0xcd, 0x4a, 0xc3, 0x40, - 0x14, 0x46, 0x27, 0xfd, 0x49, 0xd3, 0xab, 0xc2, 0x30, 0x0f, 0x30, 0xe0, 0x36, 0xd0, 0x66, 0xe1, - 0xc6, 0x6d, 0x93, 0x56, 0x08, 0xa4, 0xba, 0xa8, 0x06, 0x71, 0x37, 0x19, 0x87, 0x18, 0x4b, 0x66, - 0x86, 0xc9, 0xad, 0xc6, 0xb7, 0xf0, 0xb1, 0x5c, 0x76, 0xe9, 0x52, 0x92, 0x17, 0x91, 0x54, 0x5c, - 0x7e, 0xf0, 0x9d, 0x03, 0x07, 0x82, 0xb7, 0x7a, 0x69, 0x9d, 0x41, 0xc3, 0xfc, 0x46, 0xba, 0xca, - 0x62, 0x78, 0x0d, 0x7e, 0xbe, 0xbd, 0xff, 0xb0, 0x8a, 0x9d, 0xc1, 0x2c, 0xbd, 0xcd, 0x57, 0x59, - 0xba, 0xa6, 0x84, 0xcd, 0x61, 0xba, 0xab, 0x85, 0x43, 0xea, 0xb1, 0x19, 0x8c, 0x93, 0x2c, 0xa6, - 0x23, 0x76, 0x01, 0xf3, 0x24, 0x8b, 0xb7, 0xa2, 0x41, 0xe5, 0xe8, 0x65, 0xb8, 0x03, 0xb8, 0x2b, - 0x5e, 0x95, 0xc4, 0x7f, 0xfa, 0x41, 0xef, 0xb5, 0x79, 0xd7, 0x94, 0xb0, 0x73, 0x08, 0x12, 0xa3, - 0xd1, 0x09, 0x39, 0x08, 0x02, 0x98, 0xdc, 0x1c, 0xb4, 0xa4, 0xa3, 0xe1, 0xb4, 0x69, 0xf1, 0x34, - 0xc6, 0x83, 0x37, 0x17, 0x8e, 0x4e, 0x18, 0x80, 0xbf, 0x69, 0x51, 0xe9, 0x67, 0x3a, 0x8d, 0xd7, - 0x5f, 0x1d, 0xf7, 0x8e, 0x1d, 0xf7, 0x7e, 0x3a, 0xee, 0x7d, 0xf6, 0x9c, 0x1c, 0x7b, 0x4e, 0xbe, - 0x7b, 0x4e, 0x9e, 0xc2, 0xb2, 0xc2, 0x97, 0x43, 0xb1, 0x94, 0xa6, 0x8e, 0xd2, 0x78, 0xf5, 0xb8, - 0xa8, 0x4c, 0x54, 0x9a, 0x45, 0x55, 0x88, 0x36, 0xb2, 0x42, 0xee, 0x45, 0xa9, 0x9a, 0xe8, 0x2f, - 0xaa, 0xf0, 0x4f, 0x8d, 0x57, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x1c, 0x3b, 0xcd, 0x3b, 0xef, - 0x00, 0x00, 0x00, + // 242 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x34, 0x8f, 0x41, 0x4e, 0x83, 0x40, + 0x18, 0x46, 0x87, 0xd2, 0x52, 0xfa, 0xab, 0xc9, 0x64, 0x0e, 0x30, 0x07, 0x20, 0x69, 0x59, 0xb8, + 0x71, 0x5b, 0x68, 0x4d, 0x48, 0xa8, 0x2e, 0xaa, 0xc4, 0xb8, 0x1b, 0xc6, 0x09, 0x62, 0xc3, 0x0c, + 0x19, 0xfe, 0x2a, 0xde, 0xc2, 0x63, 0xb9, 0xec, 0xd2, 0xa5, 0x81, 0x8b, 0x18, 0x30, 0x5d, 0x7e, + 0xc9, 0xf7, 0x5e, 0xf2, 0xc0, 0x7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