diff --git a/cli/cmd/deploy.go b/cli/cmd/deploy.go index ce4c23c877..53882fa216 100644 --- a/cli/cmd/deploy.go +++ b/cli/cmd/deploy.go @@ -120,16 +120,22 @@ var _deployCmd = &cobra.Command{ exit.Error(err) } fmt.Println(string(bytes)) - return case flags.MixedOutputType: err := mixedPrint(deployResults) if err != nil { exit.Error(err) } - return case flags.PrettyOutputType: message := deployMessage(deployResults, env.Name) - print.BoldFirstBlock(message) + if didAnyResultsError(deployResults) { + print.StderrBoldFirstBlock(message) + } else { + print.BoldFirstBlock(message) + } + } + + if didAnyResultsError(deployResults) { + exit.Error(nil) } }, } @@ -297,6 +303,15 @@ func didAllResultsError(results []schema.DeployResult) bool { return true } +func didAnyResultsError(results []schema.DeployResult) bool { + for _, result := range results { + if result.Error != "" { + return true + } + } + return false +} + func getAPICommandsMessage(results []schema.DeployResult, envName string) string { apiName := "" if len(results) == 1 { diff --git a/pkg/lib/errors/message.go b/pkg/lib/errors/message.go index 6606f183cb..c174adf5b2 100644 --- a/pkg/lib/errors/message.go +++ b/pkg/lib/errors/message.go @@ -17,7 +17,6 @@ limitations under the License. package errors import ( - "os" "strings" "github.com/aws/aws-sdk-go/aws/awserr" @@ -25,7 +24,7 @@ import ( ) func PrintError(err error, strs ...string) { - os.Stderr.WriteString(ErrorStr(err, strs...) + "\n") + print.StderrPrintln(ErrorStr(err, strs...)) // PrintStacktrace(err) } diff --git a/pkg/lib/exit/exit.go b/pkg/lib/exit/exit.go index 78564a04bb..86af746d16 100644 --- a/pkg/lib/exit/exit.go +++ b/pkg/lib/exit/exit.go @@ -33,11 +33,11 @@ func Error(err error, wrapStrs ...string) { err = errors.Wrap(err, str) } - if !errors.IsNoTelemetry(err) { + if err != nil && !errors.IsNoTelemetry(err) { telemetry.Error(err) } - if !errors.IsNoPrint(err) { + if err != nil && !errors.IsNoPrint(err) { errors.PrintErrorForUser(err) } @@ -51,7 +51,7 @@ func Panic(err error, wrapStrs ...string) { err = errors.Wrap(err, str) } - if !errors.IsNoTelemetry(err) { + if err != nil && !errors.IsNoTelemetry(err) { telemetry.Error(err) } diff --git a/pkg/lib/print/print.go b/pkg/lib/print/print.go index b5942064da..7445043949 100644 --- a/pkg/lib/print/print.go +++ b/pkg/lib/print/print.go @@ -45,14 +45,14 @@ func StderrBoldFirstLine(msg string) { msgParts := strings.Split(msg, "\n") if len(msgParts[0]) > _maxBoldLength { - os.Stderr.WriteString(msg + "\n") + StderrPrintln(msg) return } - os.Stderr.WriteString(console.Bold(msgParts[0]) + "\n") + StderrPrintln(console.Bold(msgParts[0])) if len(msgParts) > 1 { - os.Stderr.WriteString(strings.Join(msgParts[1:], "\n") + "\n") + StderrPrintln(strings.Join(msgParts[1:], "\n")) } } @@ -71,7 +71,26 @@ func BoldFirstBlock(msg string) { } } +func StderrBoldFirstBlock(msg string) { + msgParts := strings.Split(msg, "\n\n") + + if len(msgParts[0]) > _maxBoldLength { + StderrPrintln(msg) + return + } + + StderrPrintln(console.Bold(msgParts[0])) + + if len(msgParts) > 1 { + StderrPrintln("\n" + strings.Join(msgParts[1:], "\n\n")) + } +} + func Dot() error { fmt.Print(".") return nil } + +func StderrPrintln(str string) { + os.Stderr.WriteString(str + "\n") +} diff --git a/pkg/workloads/cortex/client/cortex/binary/__init__.py b/pkg/workloads/cortex/client/cortex/binary/__init__.py index f7cf580015..2cd4fc2c5a 100644 --- a/pkg/workloads/cortex/client/cortex/binary/__init__.py +++ b/pkg/workloads/cortex/client/cortex/binary/__init__.py @@ -77,6 +77,7 @@ def run_cli( result = "~" output = output[:-1] if result_found: + output = output[:-1] if c == "\n": result_found = False result = result[len(MIXED_CORTEX_MARKER) : -len(MIXED_CORTEX_MARKER)] @@ -96,6 +97,9 @@ def run_cli( return result return output + if result != "": + raise CortexBinaryException(result + "\n" + process.stderr.read()) + raise CortexBinaryException(process.stderr.read())