From a7ef81d46b39f1d94c67871e3555d113e6752ca4 Mon Sep 17 00:00:00 2001 From: James Martinez Date: Wed, 13 Apr 2022 17:45:44 -0400 Subject: [PATCH] Define contract for turbine response and capture --- cmd/meroxa/turbine_cli/javascript/deploy.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/cmd/meroxa/turbine_cli/javascript/deploy.go b/cmd/meroxa/turbine_cli/javascript/deploy.go index fbca0608d..c715e2650 100644 --- a/cmd/meroxa/turbine_cli/javascript/deploy.go +++ b/cmd/meroxa/turbine_cli/javascript/deploy.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "os/exec" + "regexp" "strconv" "strings" @@ -13,15 +14,25 @@ import ( "github.com/meroxa/cli/log" ) +func processError(err error, path string, output []byte) (bool, error) { + fmterr := fmt.Errorf( + "unable to determine if the Meroxa Application at %s has a Process; %s", + path, + string(output)) + return false, fmterr +} + func NeedsToBuild(path string) (bool, error) { cmd := exec.Command("npx", "turbine", "hasfunctions", path) output, err := cmd.CombinedOutput() if err != nil { - err := fmt.Errorf( - "unable to determine if the Meroxa Application at %s has a Process; %s", - path, - string(output)) - return false, err + return processError(err, path, output) + } + + r, _ := regexp.Compile("\nturbine-response: (true|false)\n") + match := r.FindString(string(output)) + if match == "" { + return processError(err, path, output) } return strconv.ParseBool(strings.TrimSpace(string(output))) }