You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(gnovm/cmd): printing all the errors from goparser (#2011)
<!-- please provide a detailed description of the changes made in this
pull request. -->
This PR aims to print all the errors that are found by the go/parser
package.
Currently the `parser.ParseFile` function returns an `scanner.ErrorList`
object that only prints the first error and a count of the remaining
errors. #1933 everything is better explained here.
**For the changes this PR introduces**:
- Create **issueWithError** function. This function will wrap the lines
of code that processed an error (before this PR changes) in order to
convert it on an **lintIssue** structure. This existent code applies a
regex to localize the parse error more precisely.
- The PR changes the behavior of run, test, and lint commands. Not they
exit with a non-zero status code as soon as we found some error while
parsing the files. This in order to not having the whole stacktrace for
some parsing file error, improving visibility.
- Add a new case on `gnovm/cmd/gno/lint.go.catchRuntimeError` to handle
and print all errors of an error with type `scanner.ErrorList`
- remove some wrapping during panic calls. This was done by simplicity
some of the calls were doing `panic(errors.Wrap(err, "parsing file
"+mfile.Name))` here err has the type scanner.ErrorList but as we're
wrapping it it would be more complex and difficult to read on
**catchRuntimeError** to identify an error with the type ErrorList
**Results:** (Using issue example)
- lint:
```cmd
-- NOW
./.: missing 'gno.mod' file (code=1).
test.gno:6: expected ';', found example (code=2).
test.gno:7: expected '}', found 'EOF' (code=2).
exit status 1
---- BEFORE
./.: missing 'gno.mod' file (code=1).
test.gno:6: expected ';', found example (and 1 more errors) (code=2).
```
- run:
```cmd
-- NOW
test.gno:6: expected ';', found example (code=2).
test.gno:7: expected '}', found 'EOF' (code=2).
exit status 1
---- BEFORE
panic: test.gno:6:5: expected ';', found example (and 1 more errors)
goroutine 1 [running]:
github.com/gnolang/gno/gnovm/pkg/gnolang.MustReadFile(...)
/Users/miguel/gnorigin/gnovm/pkg/gnolang/go2gno.go:49
main.parseFiles({0x140003b1720, 0x1, 0x1400031fb48?})
/Users/miguel/gnorigin/gnovm/cmd/gno/run.go:132 +0x27c
main.parseFiles({0x140003b09a0, 0x1, 0x0?})
/Users/miguel/gnorigin/gnovm/cmd/gno/run.go:121 +0x158
main.execRun(0x14000373230, {0x140003b09a0, 0x1, 0x1}, {0x100ca3e68, 0x140003b3bd0})
/Users/miguel/gnorigin/gnovm/cmd/gno/run.go:89 +0x174
main.newRunCmd.func1({0x0?, 0x1400019c140?}, {0x140003b09a0?, 0x0?, 0x0?})
/Users/miguel/gnorigin/gnovm/cmd/gno/run.go:35 +0x3c
github.com/gnolang/gno/tm2/pkg/commands.(*Command).Run(0x1400031fdc8?, {0x100c9af18?, 0x101249700?})
/Users/miguel/gnorigin/tm2/pkg/commands/command.go:247 +0x17c
github.com/gnolang/gno/tm2/pkg/commands.(*Command).Run(0x140003ae2c0?, {0x100c9af18?, 0x101249700?})
/Users/miguel/gnorigin/tm2/pkg/commands/command.go:251 +0x12c
github.com/gnolang/gno/tm2/pkg/commands.(*Command).ParseAndRun(0x140003ae6e0?, {0x100c9af18, 0x101249700}, {0x1400019c130?, 0x140003ae790?, 0x140003ae840?})
/Users/miguel/gnorigin/tm2/pkg/commands/command.go:132 +0x4c
github.com/gnolang/gno/tm2/pkg/commands.(*Command).Execute(0x100ca3e68?, {0x100c9af18?, 0x101249700?}, {0x1400019c130?, 0x1011a5ef8?, 0x140000021a0?})
/Users/miguel/gnorigin/tm2/pkg/commands/command.go:114 +0x28
main.main()
/Users/miguel/gnorigin/gnovm/cmd/gno/main.go:13 +0x6c
```
<details><summary>Contributors' checklist...</summary>
- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
stderrShouldContain: "../../tests/integ/several-lint-errors/main.gno:5: expected ';', found example (code=2).\n../../tests/integ/several-lint-errors/main.gno:6",
0 commit comments