Skip to content

Commit

Permalink
panic with unexpected error instead of plain error
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Sep 28, 2022
1 parent 0a9e891 commit 999bb0c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
3 changes: 2 additions & 1 deletion runtime/account_test.go
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"testing"

"github.com/onflow/cadence/runtime/errors"
"github.com/onflow/cadence/runtime/interpreter"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -816,7 +817,7 @@ func encodeArgs(argValues []cadence.Value) [][]byte {
var err error
args[i], err = json.Encode(arg)
if err != nil {
panic(fmt.Errorf("broken test: invalid argument: %w", err))
panic(errors.NewUnexpectedError("broken test: invalid argument: %w", err))
}
}
return args
Expand Down
7 changes: 3 additions & 4 deletions runtime/parser/expression.go
Expand Up @@ -19,7 +19,6 @@
package parser

import (
"fmt"
"math/big"
"strings"
"unicode/utf8"
Expand Down Expand Up @@ -199,7 +198,7 @@ func defineExpr(def any) {
func setExprNullDenotation(tokenType lexer.TokenType, nullDenotation exprNullDenotationFunc) {
current := exprNullDenotations[tokenType]
if current != nil {
panic(fmt.Errorf(
panic(errors.NewUnexpectedError(
"expression null denotation for token %s already exists",
tokenType,
))
Expand All @@ -226,7 +225,7 @@ func setExprIdentifierLeftBindingPower(keyword string, power int) {
func setExprLeftDenotation(tokenType lexer.TokenType, leftDenotation exprLeftDenotationFunc) {
current := exprLeftDenotations[tokenType]
if current != nil {
panic(fmt.Errorf(
panic(errors.NewUnexpectedError(
"expression left denotation for token %s already exists",
tokenType,
))
Expand All @@ -238,7 +237,7 @@ func setExprLeftDenotation(tokenType lexer.TokenType, leftDenotation exprLeftDen
func setExprMetaLeftDenotation(tokenType lexer.TokenType, metaLeftDenotation exprMetaLeftDenotationFunc) {
current := exprMetaLeftDenotations[tokenType]
if current != nil {
panic(fmt.Errorf(
panic(errors.NewUnexpectedError(
"expression meta left denotation for token %s already exists",
tokenType,
))
Expand Down
8 changes: 3 additions & 5 deletions runtime/parser/type.go
Expand Up @@ -19,8 +19,6 @@
package parser

import (
"fmt"

"github.com/onflow/cadence/runtime/ast"
"github.com/onflow/cadence/runtime/errors"
"github.com/onflow/cadence/runtime/parser/lexer"
Expand Down Expand Up @@ -55,7 +53,7 @@ var typeMetaLeftDenotations [lexer.TokenMax]typeMetaLeftDenotationFunc
func setTypeNullDenotation(tokenType lexer.TokenType, nullDenotation typeNullDenotationFunc) {
current := typeNullDenotations[tokenType]
if current != nil {
panic(fmt.Errorf(
panic(errors.NewUnexpectedError(
"type null denotation for token %s already exists",
tokenType,
))
Expand All @@ -74,7 +72,7 @@ func setTypeLeftBindingPower(tokenType lexer.TokenType, power int) {
func setTypeLeftDenotation(tokenType lexer.TokenType, leftDenotation typeLeftDenotationFunc) {
current := typeLeftDenotations[tokenType]
if current != nil {
panic(fmt.Errorf(
panic(errors.NewUnexpectedError(
"type left denotation for token %s already exists",
tokenType,
))
Expand All @@ -85,7 +83,7 @@ func setTypeLeftDenotation(tokenType lexer.TokenType, leftDenotation typeLeftDen
func setTypeMetaLeftDenotation(tokenType lexer.TokenType, metaLeftDenotation typeMetaLeftDenotationFunc) {
current := typeMetaLeftDenotations[tokenType]
if current != nil {
panic(fmt.Errorf(
panic(errors.NewUnexpectedError(
"type meta left denotation for token %s already exists",
tokenType,
))
Expand Down

0 comments on commit 999bb0c

Please sign in to comment.