Skip to content

Commit

Permalink
Add extended debug checking error for tracking unexpected execution e…
Browse files Browse the repository at this point in the history
…rrors
  • Loading branch information
m4ksio authored and turbolent committed Nov 23, 2020
1 parent 9337e48 commit 1030e61
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
3 changes: 3 additions & 0 deletions runtime/runtime_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type interpreterRuntimeStorage struct {
cache Cache
}

// temporary export the type for usage in ExtendedParsingCheckingError
type InterpreterRuntimeStorage = interpreterRuntimeStorage

func newInterpreterRuntimeStorage(runtimeInterface Interface) *interpreterRuntimeStorage {
highLevelStorageEnabled := false
highLevelStorage, ok := runtimeInterface.(HighLevelStorage)
Expand Down
38 changes: 36 additions & 2 deletions runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"github.com/onflow/cadence/runtime/interpreter"
"github.com/onflow/cadence/runtime/sema"
"github.com/onflow/cadence/runtime/stdlib"
"github.com/onflow/cadence/runtime/tests/checker"
"github.com/onflow/cadence/runtime/tests/utils"
)

Expand Down Expand Up @@ -3342,7 +3341,7 @@ func TestRuntimeTransactionTopLevelDeclarations(t *testing.T) {
require.IsType(t, Error{}, err)
err = err.(Error).Unwrap()

errs := checker.ExpectCheckerErrors(t, err, 1)
errs := ExpectCheckerErrors(t, err, 1)

assert.IsType(t, &sema.InvalidTopLevelDeclarationError{}, errs[0])
})
Expand Down Expand Up @@ -5052,3 +5051,38 @@ func singleIdentifierLocationResolver(t *testing.T) func(identifiers []Identifie
}
}
}

// Copied to prevent import cycle while importing from tests/checker package
// while using ExtendedParsingCheckingError
// This now required `runtime` to get access `ExtendedParsingCheckingError`
// which in turns requires `runtime` so any import of original function from
// any other module will introduce cycle
// If we decide to keep extended debug functionality beyond original
// debug possible race condition, this would need to be refactored
func ExpectCheckerErrors(t *testing.T, err error, count int) []error {
if count <= 0 && err == nil {
return nil
}

require.Error(t, err)

// Temporary to help catch checking error
ee, is := err.(*ExtendedParsingCheckingError)
if is {
err = ee.Unwrap()
}

assert.IsType(t, &sema.CheckerError{}, err)

errs := err.(*sema.CheckerError).Errors

require.Len(t, errs, count)

// Get the error message, to check that it can be successfully generated

for _, checkerErr := range errs {
_ = checkerErr.Error()
}

return errs
}

0 comments on commit 1030e61

Please sign in to comment.