3
0

Copy error handling fn from cli pkg

This way we can avoid problems when recompiling codegen bin
and invalid code has been generated
This commit is contained in:
Denis Arh
2020-11-27 10:51:34 +01:00
parent 2ac72120d6
commit b4b3e15d81
2 changed files with 21 additions and 12 deletions
+18 -8
View File
@@ -3,14 +3,12 @@ package codegen
import (
"flag"
"fmt"
"github.com/Masterminds/sprig"
"github.com/fsnotify/fsnotify"
"os"
"path/filepath"
"strings"
"text/template"
"github.com/Masterminds/sprig"
"github.com/cortezaproject/corteza-server/pkg/cli"
"github.com/fsnotify/fsnotify"
)
func Proc() {
@@ -138,7 +136,7 @@ func Proc() {
}
watcher, err = fsnotify.NewWatcher()
cli.HandleError(err)
handleError(err)
fileList = append(fileList, templatesSrc...)
fileList = append(fileList, actionSrc...)
@@ -149,7 +147,7 @@ func Proc() {
fileList = append(fileList, optionSrc...)
for _, d := range fileList {
cli.HandleError(watcher.Add(d))
handleError(watcher.Add(d))
}
}
@@ -219,7 +217,7 @@ func Proc() {
select {
case <-watcher.Events:
case err = <-watcher.Errors:
cli.HandleError(err)
handleError(err)
}
}
}
@@ -227,8 +225,20 @@ func Proc() {
func glob(path string) []string {
src, err := filepath.Glob(path)
if err != nil {
cli.HandleError(fmt.Errorf("failed to glob %q: %w", path, err))
handleError(fmt.Errorf("failed to glob %q: %w", path, err))
}
return src
}
// Similar to cli.HandleError but without cli pkg dependencies
//
// pkg/cli deps can give us issues when generating go files with invalid code
func handleError(err error) {
if err == nil {
return
}
_, _ = fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}