Skip to content

Commit

Permalink
fix proto and recover err info
Browse files Browse the repository at this point in the history
  • Loading branch information
scottafk committed Jan 6, 2022
1 parent 085ce36 commit 6cc27b8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 60 deletions.
2 changes: 1 addition & 1 deletion packages/pb/vm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
75 changes: 39 additions & 36 deletions packages/script/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
46 changes: 23 additions & 23 deletions packages/script/vm.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6cc27b8

Please sign in to comment.