From 859a64b48ce91cd793973a60f1a42af7c867c1aa Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Wed, 1 May 2024 10:35:09 +0200 Subject: [PATCH 1/7] feat: printing all the errors from goparser --- gnovm/cmd/gno/lint.go | 45 +++++++++++--------------------------- gnovm/cmd/gno/run.go | 15 +++++++++---- gnovm/cmd/gno/test.go | 11 +++++++++- gnovm/cmd/gno/util.go | 41 ++++++++++++++++++++++++++++++++++ gnovm/pkg/gnolang/nodes.go | 2 +- 5 files changed, 76 insertions(+), 38 deletions(-) diff --git a/gnovm/cmd/gno/lint.go b/gnovm/cmd/gno/lint.go index e2a7e53fb69..c22ceeefc5c 100644 --- a/gnovm/cmd/gno/lint.go +++ b/gnovm/cmd/gno/lint.go @@ -5,6 +5,7 @@ import ( "errors" "flag" "fmt" + "go/scanner" "os" "path/filepath" "regexp" @@ -67,11 +68,7 @@ func execLint(cfg *lintCfg, args []string, io commands.IO) error { return fmt.Errorf("list packages from args: %w", err) } - hasError := false - addIssue := func(issue lintIssue) { - hasError = true - fmt.Fprint(io.Err(), issue.String()+"\n") - } + issueAdder := newIssueAdder(io.Err()) for _, pkgPath := range pkgPaths { if verbose { @@ -81,7 +78,7 @@ func execLint(cfg *lintCfg, args []string, io commands.IO) error { // Check if 'gno.mod' exists gnoModPath := filepath.Join(pkgPath, "gno.mod") if !osm.FileExists(gnoModPath) { - addIssue(lintIssue{ + issueAdder.addIssue(lintIssue{ Code: lintNoGnoMod, Confidence: 1, Location: pkgPath, @@ -90,7 +87,7 @@ func execLint(cfg *lintCfg, args []string, io commands.IO) error { } // Handle runtime errors - catchRuntimeError(pkgPath, addIssue, func() { + catchRuntimeError(pkgPath, issueAdder, func() { stdout, stdin, stderr := io.Out(), io.In(), io.Err() testStore := tests.TestStore( rootDir, "", @@ -135,7 +132,7 @@ func execLint(cfg *lintCfg, args []string, io commands.IO) error { // TODO: Add more checkers } - if hasError && cfg.setExitStatus != 0 { + if issueAdder.inError && cfg.setExitStatus != 0 { os.Exit(cfg.setExitStatus) } @@ -164,7 +161,7 @@ func guessSourcePath(pkg, source string) string { // XXX: Ideally, error handling should encapsulate location details within a dedicated error type. var reParseRecover = regexp.MustCompile(`^([^:]+):(\d+)(?::\d+)?:? *(.*)$`) -func catchRuntimeError(pkgPath string, addIssue func(issue lintIssue), action func()) { +func catchRuntimeError(pkgPath string, issueAdder *issueAdder, action func()) { defer func() { // Errors catched here mostly come from: gnovm/pkg/gnolang/preprocess.go r := recover() @@ -172,36 +169,20 @@ func catchRuntimeError(pkgPath string, addIssue func(issue lintIssue), action fu return } - var err error switch verr := r.(type) { case *gno.PreprocessError: - err = verr.Unwrap() + issueAdder.addError(pkgPath, verr) + case scanner.ErrorList: + for _, err := range verr { + issueAdder.addError(pkgPath, err) + } case error: - err = verr + issueAdder.addError(pkgPath, verr) case string: - err = errors.New(verr) + issueAdder.addError(pkgPath, errors.New(verr)) default: panic(r) } - - var issue lintIssue - issue.Confidence = 1 - issue.Code = lintGnoError - - parsedError := strings.TrimSpace(err.Error()) - parsedError = strings.TrimPrefix(parsedError, pkgPath+"/") - - matches := reParseRecover.FindStringSubmatch(parsedError) - if len(matches) == 4 { - sourcepath := guessSourcePath(pkgPath, matches[1]) - issue.Location = fmt.Sprintf("%s:%s", sourcepath, matches[2]) - issue.Msg = strings.TrimSpace(matches[3]) - } else { - issue.Location = fmt.Sprintf("%s:0", filepath.Clean(pkgPath)) - issue.Msg = err.Error() - } - - addIssue(issue) }() action() diff --git a/gnovm/cmd/gno/run.go b/gnovm/cmd/gno/run.go index 0c5218613a9..004ee456f32 100644 --- a/gnovm/cmd/gno/run.go +++ b/gnovm/cmd/gno/run.go @@ -102,7 +102,7 @@ func execRun(cfg *runCfg, args []string, io commands.IO) error { } // read files - files, err := parseFiles(args) + files, err := parseFiles(args, newIssueAdder(stderr)) if err != nil { return err } @@ -135,7 +135,7 @@ func execRun(cfg *runCfg, args []string, io commands.IO) error { return nil } -func parseFiles(fnames []string) ([]*gno.FileNode, error) { +func parseFiles(fnames []string, issueAdder *issueAdder) ([]*gno.FileNode, error) { files := make([]*gno.FileNode, 0, len(fnames)) for _, fname := range fnames { if s, err := os.Stat(fname); err == nil && s.IsDir() { @@ -143,7 +143,7 @@ func parseFiles(fnames []string) ([]*gno.FileNode, error) { if err != nil { return nil, err } - subFiles, err := parseFiles(subFns) + subFiles, err := parseFiles(subFns, issueAdder) if err != nil { return nil, err } @@ -154,7 +154,14 @@ func parseFiles(fnames []string) ([]*gno.FileNode, error) { // in either case not a file we can parse. return nil, err } - files = append(files, gno.MustReadFile(fname)) + + catchRuntimeError(fname, issueAdder, func() { + files = append(files, gno.MustReadFile(fname)) + }) + } + + if issueAdder.inError { + os.Exit(1) } return files, nil } diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index 8b48e10d422..3df56d65437 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -325,7 +325,16 @@ func gnoTestPkg( memPkg := gno.ReadMemPackage(pkgPath, gnoPkgPath) // tfiles, ifiles := gno.ParseMemPackageTests(memPkg) - tfiles, ifiles := parseMemPackageTests(memPkg) + issueAdder := newIssueAdder(stderr) + var tfiles, ifiles *gno.FileSet + + catchRuntimeError(gnoPkgPath, issueAdder, func() { + tfiles, ifiles = parseMemPackageTests(memPkg) + }) + + if issueAdder.inError { + os.Exit(1) + } testPkgName := getPkgNameFromFileset(ifiles) // run test files in pkg diff --git a/gnovm/cmd/gno/util.go b/gnovm/cmd/gno/util.go index 30d8f808d04..25c605e5542 100644 --- a/gnovm/cmd/gno/util.go +++ b/gnovm/cmd/gno/util.go @@ -326,3 +326,44 @@ func prettySize(nb int64) string { } return fmt.Sprintf("%.1f%c", float64(nb)/float64(div), "kMGTPE"[exp]) } + +type issueAdder struct { + inError bool + stderr io.WriteCloser +} + +func newIssueAdder(sdterr io.WriteCloser) *issueAdder { + return &issueAdder{ + stderr: sdterr, + } +} + +func (i *issueAdder) hasError() bool { + return i.inError +} + +func (i *issueAdder) addError(pkgPath string, err error) { + var issue lintIssue + issue.Confidence = 1 + issue.Code = lintGnoError + + parsedError := strings.TrimSpace(err.Error()) + parsedError = strings.TrimPrefix(parsedError, pkgPath+"/") + + matches := reParseRecover.FindStringSubmatch(parsedError) + if len(matches) == 4 { + sourcepath := guessSourcePath(pkgPath, matches[1]) + issue.Location = fmt.Sprintf("%s:%s", sourcepath, matches[2]) + issue.Msg = strings.TrimSpace(matches[3]) + } else { + issue.Location = fmt.Sprintf("%s:0", filepath.Clean(pkgPath)) + issue.Msg = err.Error() + } + + i.addIssue(issue) +} + +func (i *issueAdder) addIssue(issue lintIssue) { + fmt.Fprint(i.stderr, issue.String()+"\n") + i.inError = true +} diff --git a/gnovm/pkg/gnolang/nodes.go b/gnovm/pkg/gnolang/nodes.go index 8f2c5054a8a..6f1584dcc28 100644 --- a/gnovm/pkg/gnolang/nodes.go +++ b/gnovm/pkg/gnolang/nodes.go @@ -1179,7 +1179,7 @@ func ParseMemPackage(memPkg *std.MemPackage) (fset *FileSet) { } n, err := ParseFile(mfile.Name, mfile.Body) if err != nil { - panic(errors.Wrap(err, "parsing file "+mfile.Name)) + panic(err) } if memPkg.Name != string(n.PkgName) { panic(fmt.Sprintf( From b2ff4f8cb7068b9d36b39fa20b6cddc469f7b46b Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Wed, 1 May 2024 12:49:38 +0200 Subject: [PATCH 2/7] Fix linter --- gnovm/cmd/gno/lint.go | 2 +- gnovm/cmd/gno/run.go | 2 +- gnovm/cmd/gno/test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gnovm/cmd/gno/lint.go b/gnovm/cmd/gno/lint.go index c22ceeefc5c..672445600f4 100644 --- a/gnovm/cmd/gno/lint.go +++ b/gnovm/cmd/gno/lint.go @@ -132,7 +132,7 @@ func execLint(cfg *lintCfg, args []string, io commands.IO) error { // TODO: Add more checkers } - if issueAdder.inError && cfg.setExitStatus != 0 { + if issueAdder.hasError() && cfg.setExitStatus != 0 { os.Exit(cfg.setExitStatus) } diff --git a/gnovm/cmd/gno/run.go b/gnovm/cmd/gno/run.go index 004ee456f32..770eb95872c 100644 --- a/gnovm/cmd/gno/run.go +++ b/gnovm/cmd/gno/run.go @@ -160,7 +160,7 @@ func parseFiles(fnames []string, issueAdder *issueAdder) ([]*gno.FileNode, error }) } - if issueAdder.inError { + if issueAdder.hasError() { os.Exit(1) } return files, nil diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index 3df56d65437..ac028f4ac1e 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -332,7 +332,7 @@ func gnoTestPkg( tfiles, ifiles = parseMemPackageTests(memPkg) }) - if issueAdder.inError { + if issueAdder.hasError() { os.Exit(1) } testPkgName := getPkgNameFromFileset(ifiles) From b9a28eadec93c24d28cf755bf4558ad71afdab4d Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Thu, 2 May 2024 20:18:04 +0200 Subject: [PATCH 3/7] Simplify code --- gnovm/cmd/gno/lint.go | 45 ++++++++++++++++++++++++++++++++----------- gnovm/cmd/gno/run.go | 12 +++++++----- gnovm/cmd/gno/test.go | 7 +++---- gnovm/cmd/gno/util.go | 41 --------------------------------------- 4 files changed, 44 insertions(+), 61 deletions(-) diff --git a/gnovm/cmd/gno/lint.go b/gnovm/cmd/gno/lint.go index 672445600f4..6340d609f6e 100644 --- a/gnovm/cmd/gno/lint.go +++ b/gnovm/cmd/gno/lint.go @@ -6,6 +6,7 @@ import ( "flag" "fmt" "go/scanner" + "io" "os" "path/filepath" "regexp" @@ -68,7 +69,7 @@ func execLint(cfg *lintCfg, args []string, io commands.IO) error { return fmt.Errorf("list packages from args: %w", err) } - issueAdder := newIssueAdder(io.Err()) + hasError := false for _, pkgPath := range pkgPaths { if verbose { @@ -78,16 +79,17 @@ func execLint(cfg *lintCfg, args []string, io commands.IO) error { // Check if 'gno.mod' exists gnoModPath := filepath.Join(pkgPath, "gno.mod") if !osm.FileExists(gnoModPath) { - issueAdder.addIssue(lintIssue{ + issue := lintIssue{ Code: lintNoGnoMod, Confidence: 1, Location: pkgPath, Msg: "missing 'gno.mod' file", - }) + } + fmt.Fprint(io.Err(), issue.String()+"\n") } // Handle runtime errors - catchRuntimeError(pkgPath, issueAdder, func() { + hasError = catchRuntimeError(pkgPath, io.Err(), func() { stdout, stdin, stderr := io.Out(), io.In(), io.Err() testStore := tests.TestStore( rootDir, "", @@ -132,7 +134,7 @@ func execLint(cfg *lintCfg, args []string, io commands.IO) error { // TODO: Add more checkers } - if issueAdder.hasError() && cfg.setExitStatus != 0 { + if hasError && cfg.setExitStatus != 0 { os.Exit(cfg.setExitStatus) } @@ -161,31 +163,32 @@ func guessSourcePath(pkg, source string) string { // XXX: Ideally, error handling should encapsulate location details within a dedicated error type. var reParseRecover = regexp.MustCompile(`^([^:]+):(\d+)(?::\d+)?:? *(.*)$`) -func catchRuntimeError(pkgPath string, issueAdder *issueAdder, action func()) { +func catchRuntimeError(pkgPath string, stderr io.WriteCloser, action func()) (hasError bool) { defer func() { // Errors catched here mostly come from: gnovm/pkg/gnolang/preprocess.go r := recover() if r == nil { return } - + hasError = true switch verr := r.(type) { case *gno.PreprocessError: - issueAdder.addError(pkgPath, verr) + fmt.Fprint(stderr, issueWithError(pkgPath, verr).String()+"\n") case scanner.ErrorList: for _, err := range verr { - issueAdder.addError(pkgPath, err) + fmt.Fprint(stderr, issueWithError(pkgPath, err).String()+"\n") } case error: - issueAdder.addError(pkgPath, verr) + fmt.Fprint(stderr, issueWithError(pkgPath, verr).String()+"\n") case string: - issueAdder.addError(pkgPath, errors.New(verr)) + fmt.Fprint(stderr, issueWithError(pkgPath, errors.New(verr)).String()+"\n") default: panic(r) } }() action() + return } type lintCode int @@ -210,3 +213,23 @@ func (i lintIssue) String() string { // TODO: consider crafting a doc URL based on Code. return fmt.Sprintf("%s: %s (code=%d).", i.Location, i.Msg, i.Code) } + +func issueWithError(pkgPath string, err error) lintIssue { + var issue lintIssue + issue.Confidence = 1 + issue.Code = lintGnoError + + parsedError := strings.TrimSpace(err.Error()) + parsedError = strings.TrimPrefix(parsedError, pkgPath+"/") + + matches := reParseRecover.FindStringSubmatch(parsedError) + if len(matches) == 4 { + sourcepath := guessSourcePath(pkgPath, matches[1]) + issue.Location = fmt.Sprintf("%s:%s", sourcepath, matches[2]) + issue.Msg = strings.TrimSpace(matches[3]) + } else { + issue.Location = fmt.Sprintf("%s:0", filepath.Clean(pkgPath)) + issue.Msg = err.Error() + } + return issue +} diff --git a/gnovm/cmd/gno/run.go b/gnovm/cmd/gno/run.go index 770eb95872c..65315909f72 100644 --- a/gnovm/cmd/gno/run.go +++ b/gnovm/cmd/gno/run.go @@ -5,6 +5,7 @@ import ( "errors" "flag" "fmt" + "io" "os" "path/filepath" "strings" @@ -102,7 +103,7 @@ func execRun(cfg *runCfg, args []string, io commands.IO) error { } // read files - files, err := parseFiles(args, newIssueAdder(stderr)) + files, err := parseFiles(args, stderr) if err != nil { return err } @@ -135,15 +136,16 @@ func execRun(cfg *runCfg, args []string, io commands.IO) error { return nil } -func parseFiles(fnames []string, issueAdder *issueAdder) ([]*gno.FileNode, error) { +func parseFiles(fnames []string, stderr io.WriteCloser) ([]*gno.FileNode, error) { files := make([]*gno.FileNode, 0, len(fnames)) + var hasError bool for _, fname := range fnames { if s, err := os.Stat(fname); err == nil && s.IsDir() { subFns, err := listNonTestFiles(fname) if err != nil { return nil, err } - subFiles, err := parseFiles(subFns, issueAdder) + subFiles, err := parseFiles(subFns, stderr) if err != nil { return nil, err } @@ -155,12 +157,12 @@ func parseFiles(fnames []string, issueAdder *issueAdder) ([]*gno.FileNode, error return nil, err } - catchRuntimeError(fname, issueAdder, func() { + hasError = catchRuntimeError(fname, stderr, func() { files = append(files, gno.MustReadFile(fname)) }) } - if issueAdder.hasError() { + if hasError { os.Exit(1) } return files, nil diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index ac028f4ac1e..e09e06c0418 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -325,14 +325,13 @@ func gnoTestPkg( memPkg := gno.ReadMemPackage(pkgPath, gnoPkgPath) // tfiles, ifiles := gno.ParseMemPackageTests(memPkg) - issueAdder := newIssueAdder(stderr) var tfiles, ifiles *gno.FileSet - catchRuntimeError(gnoPkgPath, issueAdder, func() { + hasError := catchRuntimeError(gnoPkgPath, stderr, func() { tfiles, ifiles = parseMemPackageTests(memPkg) }) - if issueAdder.hasError() { + if hasError { os.Exit(1) } testPkgName := getPkgNameFromFileset(ifiles) @@ -648,7 +647,7 @@ func parseMemPackageTests(memPkg *std.MemPackage) (tset, itset *gno.FileSet) { } n, err := gno.ParseFile(mfile.Name, mfile.Body) if err != nil { - panic(errors.Wrap(err, "parsing file "+mfile.Name)) + panic(err) } if n == nil { panic("should not happen") diff --git a/gnovm/cmd/gno/util.go b/gnovm/cmd/gno/util.go index 25c605e5542..30d8f808d04 100644 --- a/gnovm/cmd/gno/util.go +++ b/gnovm/cmd/gno/util.go @@ -326,44 +326,3 @@ func prettySize(nb int64) string { } return fmt.Sprintf("%.1f%c", float64(nb)/float64(div), "kMGTPE"[exp]) } - -type issueAdder struct { - inError bool - stderr io.WriteCloser -} - -func newIssueAdder(sdterr io.WriteCloser) *issueAdder { - return &issueAdder{ - stderr: sdterr, - } -} - -func (i *issueAdder) hasError() bool { - return i.inError -} - -func (i *issueAdder) addError(pkgPath string, err error) { - var issue lintIssue - issue.Confidence = 1 - issue.Code = lintGnoError - - parsedError := strings.TrimSpace(err.Error()) - parsedError = strings.TrimPrefix(parsedError, pkgPath+"/") - - matches := reParseRecover.FindStringSubmatch(parsedError) - if len(matches) == 4 { - sourcepath := guessSourcePath(pkgPath, matches[1]) - issue.Location = fmt.Sprintf("%s:%s", sourcepath, matches[2]) - issue.Msg = strings.TrimSpace(matches[3]) - } else { - issue.Location = fmt.Sprintf("%s:0", filepath.Clean(pkgPath)) - issue.Msg = err.Error() - } - - i.addIssue(issue) -} - -func (i *issueAdder) addIssue(issue lintIssue) { - fmt.Fprint(i.stderr, issue.String()+"\n") - i.inError = true -} From 7ce8ca4a351ae24be4ef453cb5aa2bc549d87acf Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Wed, 8 May 2024 13:53:25 +0200 Subject: [PATCH 4/7] Add lint test --- gnovm/cmd/gno/lint.go | 3 ++- gnovm/cmd/gno/lint_test.go | 7 +++++-- gnovm/tests/integ/several-lint-errors/gno.mod | 1 + gnovm/tests/integ/several-lint-errors/main.gno | 7 +++++++ 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 gnovm/tests/integ/several-lint-errors/gno.mod create mode 100644 gnovm/tests/integ/several-lint-errors/main.gno diff --git a/gnovm/cmd/gno/lint.go b/gnovm/cmd/gno/lint.go index 6340d609f6e..b60c20a9d1e 100644 --- a/gnovm/cmd/gno/lint.go +++ b/gnovm/cmd/gno/lint.go @@ -173,7 +173,8 @@ func catchRuntimeError(pkgPath string, stderr io.WriteCloser, action func()) (ha hasError = true switch verr := r.(type) { case *gno.PreprocessError: - fmt.Fprint(stderr, issueWithError(pkgPath, verr).String()+"\n") + err := verr.Unwrap() + fmt.Fprint(stderr, issueWithError(pkgPath, err).String()+"\n") case scanner.ErrorList: for _, err := range verr { fmt.Fprint(stderr, issueWithError(pkgPath, err).String()+"\n") diff --git a/gnovm/cmd/gno/lint_test.go b/gnovm/cmd/gno/lint_test.go index 5773ae0a06f..1c27981ae92 100644 --- a/gnovm/cmd/gno/lint_test.go +++ b/gnovm/cmd/gno/lint_test.go @@ -17,8 +17,11 @@ func TestLintApp(t *testing.T) { args: []string{"lint", "--set-exit-status=0", "../../tests/integ/package_not_declared/main.gno"}, stderrShouldContain: "main.gno:4: name fmt not declared (code=2).", }, { - args: []string{"lint", "--set-exit-status=0", "../../tests/integ/run_main/"}, - stderrShouldContain: "./../../tests/integ/run_main: missing 'gno.mod' file (code=1).", + args: []string{"lint", "--set-exit-status=0", "../../tests/integ/several-lint-errors/main.gno"}, + stderrShouldContain: "main.gno:6: expected ';', found example (code=2).\n../../tests/integ/several-lint-errors/main.gno:7: expected '}', found 'EOF' (code=2)", + }, { + args: []string{"lint", "--set-exit-status=0", "../../tests/integ/run-main/"}, + stderrShouldContain: "./../../tests/integ/run-main: missing 'gno.mod' file (code=1).", }, { args: []string{"lint", "--set-exit-status=0", "../../tests/integ/minimalist_gnomod/"}, // TODO: raise an error because there is a gno.mod, but no .gno files diff --git a/gnovm/tests/integ/several-lint-errors/gno.mod b/gnovm/tests/integ/several-lint-errors/gno.mod new file mode 100644 index 00000000000..88485411822 --- /dev/null +++ b/gnovm/tests/integ/several-lint-errors/gno.mod @@ -0,0 +1 @@ +module gno.land/tests/severalerrors \ No newline at end of file diff --git a/gnovm/tests/integ/several-lint-errors/main.gno b/gnovm/tests/integ/several-lint-errors/main.gno new file mode 100644 index 00000000000..26ac4986bea --- /dev/null +++ b/gnovm/tests/integ/several-lint-errors/main.gno @@ -0,0 +1,7 @@ +// a.gno example +package main + +func main() { + for { + _ example +} \ No newline at end of file From 4f101d8bb07a17741d2bd6935f313c76cdf37b7b Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Wed, 8 May 2024 14:14:38 +0200 Subject: [PATCH 5/7] Fix tests --- gnovm/cmd/gno/lint.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gnovm/cmd/gno/lint.go b/gnovm/cmd/gno/lint.go index b60c20a9d1e..d6bc5649671 100644 --- a/gnovm/cmd/gno/lint.go +++ b/gnovm/cmd/gno/lint.go @@ -79,6 +79,7 @@ func execLint(cfg *lintCfg, args []string, io commands.IO) error { // Check if 'gno.mod' exists gnoModPath := filepath.Join(pkgPath, "gno.mod") if !osm.FileExists(gnoModPath) { + hasError = true issue := lintIssue{ Code: lintNoGnoMod, Confidence: 1, @@ -89,7 +90,7 @@ func execLint(cfg *lintCfg, args []string, io commands.IO) error { } // Handle runtime errors - hasError = catchRuntimeError(pkgPath, io.Err(), func() { + hasError = hasError || catchRuntimeError(pkgPath, io.Err(), func() { stdout, stdin, stderr := io.Out(), io.In(), io.Err() testStore := tests.TestStore( rootDir, "", From 91a66afa7749be834a603cd69f64ca6f897e2918 Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Tue, 21 May 2024 18:00:14 +0200 Subject: [PATCH 6/7] fix remarks on review --- gnovm/cmd/gno/lint.go | 14 +++++++------- gnovm/tests/integ/several-lint-errors/main.gno | 1 - 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/gnovm/cmd/gno/lint.go b/gnovm/cmd/gno/lint.go index d6bc5649671..c1974094da0 100644 --- a/gnovm/cmd/gno/lint.go +++ b/gnovm/cmd/gno/lint.go @@ -90,7 +90,7 @@ func execLint(cfg *lintCfg, args []string, io commands.IO) error { } // Handle runtime errors - hasError = hasError || catchRuntimeError(pkgPath, io.Err(), func() { + hasError = catchRuntimeError(pkgPath, io.Err(), func() { stdout, stdin, stderr := io.Out(), io.In(), io.Err() testStore := tests.TestStore( rootDir, "", @@ -130,7 +130,7 @@ func execLint(cfg *lintCfg, args []string, io commands.IO) error { } tm.RunFiles(testfiles.Files...) - }) + }) || hasError // TODO: Add more checkers } @@ -175,15 +175,15 @@ func catchRuntimeError(pkgPath string, stderr io.WriteCloser, action func()) (ha switch verr := r.(type) { case *gno.PreprocessError: err := verr.Unwrap() - fmt.Fprint(stderr, issueWithError(pkgPath, err).String()+"\n") + fmt.Fprint(stderr, issueFromError(pkgPath, err).String()+"\n") case scanner.ErrorList: for _, err := range verr { - fmt.Fprint(stderr, issueWithError(pkgPath, err).String()+"\n") + fmt.Fprint(stderr, issueFromError(pkgPath, err).String()+"\n") } case error: - fmt.Fprint(stderr, issueWithError(pkgPath, verr).String()+"\n") + fmt.Fprint(stderr, issueFromError(pkgPath, verr).String()+"\n") case string: - fmt.Fprint(stderr, issueWithError(pkgPath, errors.New(verr)).String()+"\n") + fmt.Fprint(stderr, issueFromError(pkgPath, errors.New(verr)).String()+"\n") default: panic(r) } @@ -216,7 +216,7 @@ func (i lintIssue) String() string { return fmt.Sprintf("%s: %s (code=%d).", i.Location, i.Msg, i.Code) } -func issueWithError(pkgPath string, err error) lintIssue { +func issueFromError(pkgPath string, err error) lintIssue { var issue lintIssue issue.Confidence = 1 issue.Code = lintGnoError diff --git a/gnovm/tests/integ/several-lint-errors/main.gno b/gnovm/tests/integ/several-lint-errors/main.gno index 26ac4986bea..f29aa7ecd33 100644 --- a/gnovm/tests/integ/several-lint-errors/main.gno +++ b/gnovm/tests/integ/several-lint-errors/main.gno @@ -1,4 +1,3 @@ -// a.gno example package main func main() { From 10e9b14fecd856f2648913d2dc9f9c2667597864 Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Tue, 21 May 2024 21:45:33 +0200 Subject: [PATCH 7/7] Fix conflict test --- gnovm/cmd/gno/lint_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gnovm/cmd/gno/lint_test.go b/gnovm/cmd/gno/lint_test.go index 1c27981ae92..fff05726e53 100644 --- a/gnovm/cmd/gno/lint_test.go +++ b/gnovm/cmd/gno/lint_test.go @@ -18,10 +18,10 @@ func TestLintApp(t *testing.T) { stderrShouldContain: "main.gno:4: name fmt not declared (code=2).", }, { args: []string{"lint", "--set-exit-status=0", "../../tests/integ/several-lint-errors/main.gno"}, - stderrShouldContain: "main.gno:6: expected ';', found example (code=2).\n../../tests/integ/several-lint-errors/main.gno:7: expected '}', found 'EOF' (code=2)", + stderrShouldContain: "../../tests/integ/several-lint-errors/main.gno:5: expected ';', found example (code=2).\n../../tests/integ/several-lint-errors/main.gno:6", }, { - args: []string{"lint", "--set-exit-status=0", "../../tests/integ/run-main/"}, - stderrShouldContain: "./../../tests/integ/run-main: missing 'gno.mod' file (code=1).", + args: []string{"lint", "--set-exit-status=0", "../../tests/integ/run_main/"}, + stderrShouldContain: "./../../tests/integ/run_main: missing 'gno.mod' file (code=1).", }, { args: []string{"lint", "--set-exit-status=0", "../../tests/integ/minimalist_gnomod/"}, // TODO: raise an error because there is a gno.mod, but no .gno files