Skip to content

Commit

Permalink
list all errors at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
crhntr committed Jan 9, 2025
1 parent 6122807 commit 84977e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 15 additions & 3 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func CheckTemplates(wd string, config RoutesFileConfiguration) error {
return fmt.Errorf("could not find receiver %s in %s", config.ReceiverType, receiverPkgPath)
}

var errs error
var errs []error

for _, t := range templates {
var (
Expand Down Expand Up @@ -120,9 +120,21 @@ func CheckTemplates(wd string, config RoutesFileConfiguration) error {
if err := templatetype.Check(t.template.Tree, dataVar, dataVarPkg, routesPkg.Fset, newForrest(ts), fns); err != nil {
fmt.Println("ERROR", templatetype.Check(t.template.Tree, dataVar, dataVarPkg, routesPkg.Fset, newForrest(ts), fns))
fmt.Println()
errs = errors.Join(errs, err)
errs = append(errs, err)
}
}

return errs
if len(errs) == 1 {
fmt.Printf("1 error")
return errs[0]
} else if len(errs) > 0 {
fmt.Printf("%d errors\n", len(errs))
for i, err := range errs {
fmt.Printf("- %d: %s\n", i+1, err.Error())
}
return errors.Join(errs...)
}

fmt.Println("OK")
return nil
}
6 changes: 5 additions & 1 deletion cmd/muxt/check.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"io"

"github.com/crhntr/muxt"
Expand All @@ -12,5 +13,8 @@ func checkCommand(workingDirectory string, args []string, stderr io.Writer) erro
if err != nil {
return err
}
return muxt.CheckTemplates(workingDirectory, config)
if err := muxt.CheckTemplates(workingDirectory, config); err != nil {
return fmt.Errorf("fail")
}
return nil
}

0 comments on commit 84977e9

Please sign in to comment.