diff options
author | Meng-Ying Yang <garfield@dexon.org> | 2019-02-25 10:46:36 +0800 |
---|---|---|
committer | Jhih-Ming Huang <jm.huang@cobinhood.com> | 2019-05-06 10:44:04 +0800 |
commit | a7ecd58ffb2f4137bb09b084cadbbb90048fb1fe (patch) | |
tree | fa1fb3f07e8175ef9f398b7b2fe65879d7f76e8e /core/vm | |
parent | 279e7b2b35f9b90c58fae595652b0b9fd2d7a063 (diff) | |
download | dexon-a7ecd58ffb2f4137bb09b084cadbbb90048fb1fe.tar dexon-a7ecd58ffb2f4137bb09b084cadbbb90048fb1fe.tar.gz dexon-a7ecd58ffb2f4137bb09b084cadbbb90048fb1fe.tar.bz2 dexon-a7ecd58ffb2f4137bb09b084cadbbb90048fb1fe.tar.lz dexon-a7ecd58ffb2f4137bb09b084cadbbb90048fb1fe.tar.xz dexon-a7ecd58ffb2f4137bb09b084cadbbb90048fb1fe.tar.zst dexon-a7ecd58ffb2f4137bb09b084cadbbb90048fb1fe.zip |
core: vm: sqlvm: runtime entrypoing error handling
Return error.Error to reveal more information about returned error.
Diffstat (limited to 'core/vm')
-rw-r--r-- | core/vm/sqlvm/errors/errors.go | 2 | ||||
-rw-r--r-- | core/vm/sqlvm/runtime/instructions.go | 7 | ||||
-rw-r--r-- | core/vm/sqlvm/runtime/runtime.go | 10 |
3 files changed, 14 insertions, 5 deletions
diff --git a/core/vm/sqlvm/errors/errors.go b/core/vm/sqlvm/errors/errors.go index f6b91ebae..6062ae5d9 100644 --- a/core/vm/sqlvm/errors/errors.go +++ b/core/vm/sqlvm/errors/errors.go @@ -63,11 +63,13 @@ const ( ErrorCategorNil ErrorCategory = iota ErrorCategoryGrammar ErrorCategorySemantic + ErrorCategoryRuntime ) var errorCategoryMap = [...]string{ ErrorCategoryGrammar: "grammar", ErrorCategorySemantic: "semantic", + ErrorCategoryRuntime: "runtime", } func (c ErrorCategory) Error() string { 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 } } |