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 29, 2024
1 parent 683b322 commit 18fe895
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
50 changes: 26 additions & 24 deletions gnovm/cmd/gno/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,36 +172,38 @@ 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 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 {
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")
}
}
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 @@ -638,7 +638,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
for _, mfile := range memPkg.Files {
if !strings.HasSuffix(mfile.Name, ".gno") {
continue // skip this file.
Expand All @@ -648,7 +648,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
}
if n == nil {
Expand All @@ -669,8 +669,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)
}
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
}
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)
}
return fset
}
Expand Down

0 comments on commit 18fe895

Please sign in to comment.