From a7ecd58ffb2f4137bb09b084cadbbb90048fb1fe Mon Sep 17 00:00:00 2001 From: Meng-Ying Yang Date: Mon, 25 Feb 2019 10:46:36 +0800 Subject: core: vm: sqlvm: runtime entrypoing error handling Return error.Error to reveal more information about returned error. --- core/vm/sqlvm/runtime/instructions.go | 7 ++++--- core/vm/sqlvm/runtime/runtime.go | 10 ++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'core/vm/sqlvm/runtime') diff --git a/core/vm/sqlvm/runtime/instructions.go b/core/vm/sqlvm/runtime/instructions.go index b5d98f956..9ecc41231 100644 --- a/core/vm/sqlvm/runtime/instructions.go +++ b/core/vm/sqlvm/runtime/instructions.go @@ -18,9 +18,10 @@ type OpFunction func(ctx *common.Context, ops []*Operand, registers []*Operand, // Instruction represents single instruction with essential information // collection. type Instruction struct { - Op OpCode - Input []*Operand - Output int + Op OpCode + Input []*Operand + Output int + Position uint32 // ast tree position } // Raw with embedded big.Int value or byte slice which represents the real value diff --git a/core/vm/sqlvm/runtime/runtime.go b/core/vm/sqlvm/runtime/runtime.go index 3ea12f119..a8f8db7ee 100644 --- a/core/vm/sqlvm/runtime/runtime.go +++ b/core/vm/sqlvm/runtime/runtime.go @@ -3,14 +3,20 @@ package runtime import ( "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/core/vm/sqlvm/common" + "github.com/dexon-foundation/dexon/core/vm/sqlvm/errors" ) // Run is runtime entrypoint. func Run(stateDB vm.StateDB, ins []Instruction, registers []*Operand) (ret []byte, err error) { for _, in := range ins { opFunc := jumpTable[in.Op] - err = opFunc(&common.Context{}, in.Input, registers, in.Output) - if err != nil { + errCode := opFunc(&common.Context{}, in.Input, registers, in.Output) + if errCode != nil { + err = errors.Error{ + Position: in.Position, + Code: errCode.(errors.ErrorCode), + Category: errors.ErrorCategoryRuntime, + } return nil, err } } -- cgit v1.2.3