Skip to content

Commit

Permalink
Merge pull request #1165 from onflow/bastian/limit-error-printer-line…
Browse files Browse the repository at this point in the history
…-length
  • Loading branch information
turbolent committed Oct 6, 2021
2 parents 57c7254 + 3b3665b commit 5f28df0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
16 changes: 8 additions & 8 deletions runtime/deployment_test.go
Expand Up @@ -219,8 +219,8 @@ func TestRuntimeTransactionWithContractDeployment(t *testing.T) {
"error: invalid argument 0: expected type `Int`, got `Bool`\n" +
" --> 00:5:22\n" +
" |\n" +
"5 | signer.contracts.add(name: \"Test\", code: \"0a202020202020202020202020202070756220636f6e74726163742054657374207b0a202020202020202020202020202020202020696e6974285f20783a20496e7429207b7d0a20202020202020202020202020207d0a202020202020202020202020\".decodeHex(), true)\n" +
" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
"5 | signer.contracts.add(name: \"Test\", code: \"0a202020202020202020202020202070756220636f6e74726163742054657374207b0a202020... \n" +
" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
),
})
})
Expand All @@ -238,8 +238,8 @@ func TestRuntimeTransactionWithContractDeployment(t *testing.T) {
"error: invalid argument count, too many arguments: expected 0, got 1\n" +
" --> 00:5:22\n" +
" |\n" +
"5 | signer.contracts.add(name: \"Test\", code: \"0a202020202020202020202020202070756220636f6e74726163742054657374207b7d0a202020202020202020202020\".decodeHex(), 1)\n" +
" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
"5 | signer.contracts.add(name: \"Test\", code: \"0a202020202020202020202020202070756220636f6e74726163742054657374207b7d0a2020... \n" +
" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
),
})
})
Expand All @@ -257,8 +257,8 @@ func TestRuntimeTransactionWithContractDeployment(t *testing.T) {
"error: cannot deploy invalid contract\n" +
" --> 00:5:22\n" +
" |\n" +
"5 | signer.contracts.add(name: \"Test\", code: \"0a202020202020202020202020202070756220636f6e74726163742054657374207b7d0a0a202020202020202020202020202066756e2074657374436173652829207b7d0a202020202020202020202020\".decodeHex())\n" +
" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"5 | signer.contracts.add(name: \"Test\", code: \"0a202020202020202020202020202070756220636f6e74726163742054657374207b7d0a0a20... \n" +
" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"\n" +
"error: function declarations are not valid at the top-level\n" +
" --> 2a00000000000000.Test:4:18\n" +
Expand Down Expand Up @@ -311,8 +311,8 @@ func TestRuntimeTransactionWithContractDeployment(t *testing.T) {
"error: cannot deploy invalid contract\n" +
" --> 00:5:22\n" +
" |\n" +
"5 | signer.contracts.add(name: \"Test\", code: \"0a202020202020202020202020202070756220636f6e74726163742054657374207b0a2020202020202020202020202020202020207075622066756e20746573742829207b2058207d0a20202020202020202020202020207d0a202020202020202020202020\".decodeHex())\n" +
" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"5 | signer.contracts.add(name: \"Test\", code: \"0a202020202020202020202020202070756220636f6e74726163742054657374207b0a202020... \n" +
" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"\n" +
"error: cannot find variable in this scope: `X`\n" +
" --> 2a00000000000000.Test:3:35\n" +
Expand Down
15 changes: 13 additions & 2 deletions runtime/pretty/print.go
Expand Up @@ -52,6 +52,7 @@ func colorizeMeta(meta string) string {
const errorPrefix = "error"
const excerptArrow = "--> "
const excerptDots = "... "
const maxLineLength = 500

func FormatErrorMessage(message string, useColor bool) string {
// prepare prefix
Expand Down Expand Up @@ -281,7 +282,13 @@ func (p ErrorPrettyPrinter) writeCodeExcerpts(

// code line
line := lines[excerpt.startPos.Line-1]
p.writeString(line)
if len(line) > maxLineLength {
p.writeString(line[:maxLineLength])
p.writeString(excerptDots)
} else {
p.writeString(line)
}

p.writeString("\n")

// indicator line
Expand All @@ -293,7 +300,11 @@ func (p ErrorPrettyPrinter) writeCodeExcerpts(

columns := 1
if excerpt.endPos != nil && excerpt.endPos.Line == excerpt.startPos.Line {
columns = excerpt.endPos.Column - excerpt.startPos.Column + 1
endColumn := excerpt.endPos.Column
if endColumn >= maxLineLength {
endColumn = maxLineLength - 1
}
columns = endColumn - excerpt.startPos.Column + 1
}

indicator := "-"
Expand Down

0 comments on commit 5f28df0

Please sign in to comment.