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-03-26 17:48:22 +0800 |
commit | 34662769f36f2fd1b64c04cf8b5cf4db0d8fab47 (patch) | |
tree | 890c5d1f7c2c1ed8b2a322c822428dd4b136c7a2 /core | |
parent | f65914aa8824a8f7e9574c8553ed4307ebeaaa0c (diff) | |
download | dexon-34662769f36f2fd1b64c04cf8b5cf4db0d8fab47.tar dexon-34662769f36f2fd1b64c04cf8b5cf4db0d8fab47.tar.gz dexon-34662769f36f2fd1b64c04cf8b5cf4db0d8fab47.tar.bz2 dexon-34662769f36f2fd1b64c04cf8b5cf4db0d8fab47.tar.lz dexon-34662769f36f2fd1b64c04cf8b5cf4db0d8fab47.tar.xz dexon-34662769f36f2fd1b64c04cf8b5cf4db0d8fab47.tar.zst dexon-34662769f36f2fd1b64c04cf8b5cf4db0d8fab47.zip |
core: vm: sqlvm: runtime entrypoing error handling
Return error.Error to reveal more information about returned error.
Diffstat (limited to 'core')
-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 } } |