Skip to content

Commit

Permalink
fix comments on review
Browse files Browse the repository at this point in the history
  • Loading branch information
Villaquiranm committed May 30, 2024
1 parent 5109ce6 commit 6be80ff
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
46 changes: 22 additions & 24 deletions gnovm/cmd/gno/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,36 +170,34 @@ func catchRuntimeError(pkgPath string, stderr io.WriteCloser, action func()) (ha
return
}
hasError = true
printRuntimeError(r, pkgPath, stderr)
switch verr := r.(type) {
case *gno.PreprocessError:
err := verr.Unwrap()
fmt.Fprint(stderr, issueFromError(pkgPath, err).String()+"\n")
case error:
fmt.Fprint(stderr, issueFromError(pkgPath, verr).String()+"\n")
case []error:
for _, err := range verr {
errList, ok := err.(scanner.ErrorList)
if ok {
for _, errorInList := range errList {
fmt.Fprint(stderr, issueFromError(pkgPath, errorInList).String()+"\n")
}
} else {
fmt.Fprint(stderr, issueFromError(pkgPath, err).String()+"\n")

Check warning on line 187 in gnovm/cmd/gno/lint.go

View check run for this annotation

Codecov / codecov/patch

gnovm/cmd/gno/lint.go#L186-L187

Added lines #L186 - L187 were not covered by tests
}
}
case string:
fmt.Fprint(stderr, issueFromError(pkgPath, errors.New(verr)).String()+"\n")
default:
panic(r)
}
}()

action()
return
}

func printRuntimeError(r interface{}, pkgPath string, stderr io.WriteCloser) {
switch verr := r.(type) {
case *gno.PreprocessError:
err := verr.Unwrap()
fmt.Fprint(stderr, issueFromError(pkgPath, err).String()+"\n")
case scanner.ErrorList:
for _, err := range verr {
fmt.Fprint(stderr, issueFromError(pkgPath, err).String()+"\n")
}
case error:
fmt.Fprint(stderr, issueFromError(pkgPath, verr).String()+"\n")
case []error:
for _, err := range verr {
// recursive call to handle specifically each error type ex: scanner.ErrorList
printRuntimeError(err, pkgPath, stderr)
}
case string:
fmt.Fprint(stderr, issueFromError(pkgPath, errors.New(verr)).String()+"\n")
default:
panic(r)
}
}

type lintCode int

const (
Expand Down
8 changes: 4 additions & 4 deletions gnovm/cmd/gno/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ func loadTestFuncs(pkgName string, t *testFuncs, tfiles *gno.FileSet) *testFuncs
func parseMemPackageTests(memPkg *std.MemPackage) (tset, itset *gno.FileSet) {
tset = &gno.FileSet{}
itset = &gno.FileSet{}
errors := []error{}
var errs error

Check warning on line 581 in gnovm/cmd/gno/test.go

View check run for this annotation

Codecov / codecov/patch

gnovm/cmd/gno/test.go#L581

Added line #L581 was not covered by tests
for _, mfile := range memPkg.Files {
if !strings.HasSuffix(mfile.Name, ".gno") {
continue // skip this file.
Expand All @@ -588,7 +588,7 @@ func parseMemPackageTests(memPkg *std.MemPackage) (tset, itset *gno.FileSet) {
}
n, err := gno.ParseFile(mfile.Name, mfile.Body)
if err != nil {
errors = append(errors, err)
errs = multierr.Append(errs, err)
continue

Check warning on line 592 in gnovm/cmd/gno/test.go

View check run for this annotation

Codecov / codecov/patch

gnovm/cmd/gno/test.go#L591-L592

Added lines #L591 - L592 were not covered by tests
}
if n == nil {
Expand All @@ -609,8 +609,8 @@ func parseMemPackageTests(memPkg *std.MemPackage) (tset, itset *gno.FileSet) {
memPkg.Name, memPkg.Name, n.PkgName, mfile))
}
}
if len(errors) > 0 {
panic(errors)
if errorList := multierr.Errors(errs); len(errorList) > 0 {
panic(errorList)

Check warning on line 613 in gnovm/cmd/gno/test.go

View check run for this annotation

Codecov / codecov/patch

gnovm/cmd/gno/test.go#L612-L613

Added lines #L612 - L613 were not covered by tests
}
return tset, itset
}
Expand Down
9 changes: 5 additions & 4 deletions gnovm/pkg/gnolang/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/gnolang/gno/tm2/pkg/errors"
"github.com/gnolang/gno/tm2/pkg/std"
"go.uber.org/multierr"
)

// ----------------------------------------
Expand Down Expand Up @@ -1172,15 +1173,15 @@ func ReadMemPackageFromList(list []string, pkgPath string) *std.MemPackage {
// or [ParseFile] returns an error, ParseMemPackage panics.
func ParseMemPackage(memPkg *std.MemPackage) (fset *FileSet) {
fset = &FileSet{}
errors := []error{}
var errs error
for _, mfile := range memPkg.Files {
if !strings.HasSuffix(mfile.Name, ".gno") ||
endsWith(mfile.Name, []string{"_test.gno", "_filetest.gno"}) {
continue // skip spurious or test file.
}
n, err := ParseFile(mfile.Name, mfile.Body)
if err != nil {
errors = append(errors, err)
errs = multierr.Append(errs, err)
continue

Check warning on line 1185 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L1184-L1185

Added lines #L1184 - L1185 were not covered by tests
}
if memPkg.Name != string(n.PkgName) {
Expand All @@ -1191,8 +1192,8 @@ func ParseMemPackage(memPkg *std.MemPackage) (fset *FileSet) {
// add package file.
fset.AddFiles(n)
}
if len(errors) > 0 {
panic(errors)
if errorList := multierr.Errors(errs); len(errorList) > 0 {
panic(errorList)

Check warning on line 1196 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L1196

Added line #L1196 was not covered by tests
}
return fset
}
Expand Down

0 comments on commit 6be80ff

Please sign in to comment.