Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended debug #451

Merged
merged 13 commits into from
Nov 19, 2020
Merged
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: golangci/golangci-lint-action@v1
- uses: golangci/golangci-lint-action@v2
with:
version: v1.26
version: v1.29
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ build:

.PHONY: install-tools
install-tools:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GOPATH}/bin v1.26.0
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GOPATH}/bin v1.29.0

.PHONY: lint
lint:
Expand Down
6 changes: 1 addition & 5 deletions languageserver/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,8 @@ github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416/go.mod h1:NBIhNtsFMo
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/onflow/cadence/languageserver v0.9.1/go.mod h1:pnsGwScKufVurrYqRKzrBVmYZjLhQhsqKUW1MU87its=
github.com/onflow/flow-go-sdk v0.9.0 h1:eK40f6RU+cjh9ASGOPzsE38gO8VQhy3x52rnUGEWY6k=
github.com/onflow/flow-go-sdk v0.9.0/go.mod h1:FVVYKmWmUjfa1A4eIeZfBC+vFg0VmCf1TUaBowx+3AM=
github.com/onflow/flow-go-sdk v0.11.0 h1:hsUcgFZN7TZFUcP45HTF3oJKsM36ZffpZBmz2L9jnYk=
github.com/onflow/flow-go-sdk v0.11.0/go.mod h1:BKb9/8NtCDuwy91eLnv7TJMAsWR64s3EZhKp6mc790o=
github.com/onflow/flow/protobuf/go/flow v0.1.5-0.20200619174948-a3a856d16a27 h1:ZZ8njaFTOz7JyBpQwXGfFUUOc9l2urVAxQ7FpMUpfnc=
github.com/onflow/flow/protobuf/go/flow v0.1.5-0.20200619174948-a3a856d16a27/go.mod h1:kRugbzZjwQqvevJhrnnCFMJZNmoSJmxlKt6hTGXZojM=
github.com/onflow/flow/protobuf/go/flow v0.1.7 h1:BaZVc1XWkI1vx/+qvdkXnKjsWk4UFRBAg7vvfQ/u5Pk=
github.com/onflow/flow/protobuf/go/flow v0.1.7/go.mod h1:kRugbzZjwQqvevJhrnnCFMJZNmoSJmxlKt6hTGXZojM=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down Expand Up @@ -439,6 +434,7 @@ golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapK
golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
golang.org/x/tools v0.0.0-20200323144430-8dcfad9e016e/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
Expand Down
27 changes: 27 additions & 0 deletions runtime/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"strings"

"github.com/onflow/cadence/runtime/ast"
"github.com/onflow/cadence/runtime/errors"
"github.com/onflow/cadence/runtime/interpreter"
"github.com/onflow/cadence/runtime/sema"
Expand Down Expand Up @@ -216,3 +217,29 @@ func (e *TransactionParameterTypeNotStorableError) Error() string {
e.Type.QualifiedString(),
)
}

// ParsingCheckingError provides extra information about the state of the environment
// when a parsing or a checking error occurred
//
type ParsingCheckingError struct {
Err error
StorageCache Cache
Code []byte
Location Location
Options []sema.Option
UseCache bool
Program *ast.Program
Checker *sema.Checker
}

func (e *ParsingCheckingError) ChildErrors() []error {
return []error{e.Err}
}

func (e *ParsingCheckingError) Error() string {
return e.Err.Error()
}

func (e ParsingCheckingError) Unwrap() error {
return e.Err
}
41 changes: 31 additions & 10 deletions runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,20 @@ func (r *interpreterRuntime) ExecuteTransaction(

checker, err := r.parseAndCheckProgram(script, runtimeInterface, location, functions, nil, false)
if err != nil {
if err, ok := err.(*ParsingCheckingError); ok {
err.StorageCache = runtimeStorage.cache
return newError(err)
}

return newError(err)
}

transactions := checker.TransactionTypes
transactionCount := len(transactions)
if transactionCount != 1 {
return newError(InvalidTransactionCountError{Count: transactionCount})
return newError(InvalidTransactionCountError{
Count: transactionCount,
})
}

transactionType := transactions[0]
Expand Down Expand Up @@ -510,32 +517,46 @@ func (r *interpreterRuntime) parseAndCheckProgram(
) (*sema.Checker, error) {

var program *ast.Program
var checker *sema.Checker
var err error

wrapError := func(err error) error {
return &ParsingCheckingError{
Err: err,
Code: code,
Location: location,
Options: options,
UseCache: useCache,
Checker: checker,
Program: program,
}
}

if useCache {
wrapPanic(func() {
program, err = runtimeInterface.GetCachedProgram(location)
})
if err != nil {
return nil, err
return nil, wrapError(err)
}
}

if program == nil {
program, err = r.parse(location, code, runtimeInterface)
if err != nil {
return nil, err
return nil, wrapError(err)
}
}

importResolver := r.importResolver(runtimeInterface)
err = program.ResolveImports(importResolver)
if err != nil {
return nil, err
return nil, wrapError(err)
}

valueDeclarations := functions.ToValueDeclarations()

checker, err := sema.NewChecker(
checker, err = sema.NewChecker(
program,
location,
append(
Expand Down Expand Up @@ -568,12 +589,12 @@ func (r *interpreterRuntime) parseAndCheckProgram(
)...,
)
if err != nil {
return nil, err
return nil, wrapError(err)
}

err = checker.Check()
if err != nil {
return nil, err
return nil, wrapError(err)
}

// After the program has passed semantic analysis, cache the program AST.
Expand Down Expand Up @@ -976,7 +997,7 @@ func (r *interpreterRuntime) newAddPublicKeyFunction(

publicKey, err := interpreter.ByteArrayValueToByteSlice(publicKeyValue)
if err != nil {
panic(fmt.Sprintf("addPublicKey requires the first parameter to be an array"))
panic("addPublicKey requires the first parameter to be an array")
}

wrapPanic(func() {
Expand Down Expand Up @@ -1051,7 +1072,7 @@ func (r *interpreterRuntime) newSetCodeFunction(

code, err := interpreter.ByteArrayValueToByteSlice(invocation.Arguments[0])
if err != nil {
panic(fmt.Sprintf("setCode requires the first parameter to be an array of bytes ([Int])"))
panic("setCode requires the first parameter to be an array of bytes ([Int])")
}

constructorArguments := invocation.Arguments[requiredArgumentCount:]
Expand Down Expand Up @@ -1125,7 +1146,7 @@ func (r *interpreterRuntime) updateAccountCode(
}

if len(contractTypes) > 1 {
panic(fmt.Sprintf("code declares more than one contract"))
panic("code declares more than one contract")
}

// If the code declares a contract, instantiate it and store it
Expand Down
Loading