diff --git a/pkg/codegen/codegen.go b/pkg/codegen/codegen.go index 5cd7a650c..4dfb8b676 100644 --- a/pkg/codegen/codegen.go +++ b/pkg/codegen/codegen.go @@ -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) +} diff --git a/pkg/codegen/templating.go b/pkg/codegen/templating.go index a1cc7208a..8fb15b3a4 100644 --- a/pkg/codegen/templating.go +++ b/pkg/codegen/templating.go @@ -3,7 +3,6 @@ package codegen import ( "bytes" "fmt" - "github.com/cortezaproject/corteza-server/pkg/cli" "go/format" "io" "os" @@ -50,20 +49,20 @@ func WritePlainTo(tpl *template.Template, payload interface{}, tplName, dst stri buf := bytes.Buffer{} if err := tpl.ExecuteTemplate(&buf, tplName, payload); err != nil { - cli.HandleError(err) + handleError(err) } else { if dst == "" || dst == "-" { output = os.Stdout } else { if output, err = os.Create(dst); err != nil { - cli.HandleError(err) + handleError(err) } defer output.Close() } if _, err := output.Write(buf.Bytes()); err != nil { - cli.HandleError(err) + handleError(err) } } }