Skip to content

Commit 4a86780

Browse files
authored
Use error exit code when cluster fails to deploy (#1523)
1 parent fc16368 commit 4a86780

File tree

5 files changed

+48
-11
lines changed

5 files changed

+48
-11
lines changed

cli/cmd/deploy.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,22 @@ var _deployCmd = &cobra.Command{
120120
exit.Error(err)
121121
}
122122
fmt.Println(string(bytes))
123-
return
124123
case flags.MixedOutputType:
125124
err := mixedPrint(deployResults)
126125
if err != nil {
127126
exit.Error(err)
128127
}
129-
return
130128
case flags.PrettyOutputType:
131129
message := deployMessage(deployResults, env.Name)
132-
print.BoldFirstBlock(message)
130+
if didAnyResultsError(deployResults) {
131+
print.StderrBoldFirstBlock(message)
132+
} else {
133+
print.BoldFirstBlock(message)
134+
}
135+
}
136+
137+
if didAnyResultsError(deployResults) {
138+
exit.Error(nil)
133139
}
134140
},
135141
}
@@ -297,6 +303,15 @@ func didAllResultsError(results []schema.DeployResult) bool {
297303
return true
298304
}
299305

306+
func didAnyResultsError(results []schema.DeployResult) bool {
307+
for _, result := range results {
308+
if result.Error != "" {
309+
return true
310+
}
311+
}
312+
return false
313+
}
314+
300315
func getAPICommandsMessage(results []schema.DeployResult, envName string) string {
301316
apiName := "<api_name>"
302317
if len(results) == 1 {

pkg/lib/errors/message.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ limitations under the License.
1717
package errors
1818

1919
import (
20-
"os"
2120
"strings"
2221

2322
"github.com/aws/aws-sdk-go/aws/awserr"
2423
"github.com/cortexlabs/cortex/pkg/lib/print"
2524
)
2625

2726
func PrintError(err error, strs ...string) {
28-
os.Stderr.WriteString(ErrorStr(err, strs...) + "\n")
27+
print.StderrPrintln(ErrorStr(err, strs...))
2928
// PrintStacktrace(err)
3029
}
3130

pkg/lib/exit/exit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ func Error(err error, wrapStrs ...string) {
3333
err = errors.Wrap(err, str)
3434
}
3535

36-
if !errors.IsNoTelemetry(err) {
36+
if err != nil && !errors.IsNoTelemetry(err) {
3737
telemetry.Error(err)
3838
}
3939

40-
if !errors.IsNoPrint(err) {
40+
if err != nil && !errors.IsNoPrint(err) {
4141
errors.PrintErrorForUser(err)
4242
}
4343

@@ -51,7 +51,7 @@ func Panic(err error, wrapStrs ...string) {
5151
err = errors.Wrap(err, str)
5252
}
5353

54-
if !errors.IsNoTelemetry(err) {
54+
if err != nil && !errors.IsNoTelemetry(err) {
5555
telemetry.Error(err)
5656
}
5757

pkg/lib/print/print.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ func StderrBoldFirstLine(msg string) {
4545
msgParts := strings.Split(msg, "\n")
4646

4747
if len(msgParts[0]) > _maxBoldLength {
48-
os.Stderr.WriteString(msg + "\n")
48+
StderrPrintln(msg)
4949
return
5050
}
5151

52-
os.Stderr.WriteString(console.Bold(msgParts[0]) + "\n")
52+
StderrPrintln(console.Bold(msgParts[0]))
5353

5454
if len(msgParts) > 1 {
55-
os.Stderr.WriteString(strings.Join(msgParts[1:], "\n") + "\n")
55+
StderrPrintln(strings.Join(msgParts[1:], "\n"))
5656
}
5757
}
5858

@@ -71,7 +71,26 @@ func BoldFirstBlock(msg string) {
7171
}
7272
}
7373

74+
func StderrBoldFirstBlock(msg string) {
75+
msgParts := strings.Split(msg, "\n\n")
76+
77+
if len(msgParts[0]) > _maxBoldLength {
78+
StderrPrintln(msg)
79+
return
80+
}
81+
82+
StderrPrintln(console.Bold(msgParts[0]))
83+
84+
if len(msgParts) > 1 {
85+
StderrPrintln("\n" + strings.Join(msgParts[1:], "\n\n"))
86+
}
87+
}
88+
7489
func Dot() error {
7590
fmt.Print(".")
7691
return nil
7792
}
93+
94+
func StderrPrintln(str string) {
95+
os.Stderr.WriteString(str + "\n")
96+
}

pkg/workloads/cortex/client/cortex/binary/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def run_cli(
7777
result = "~"
7878
output = output[:-1]
7979
if result_found:
80+
output = output[:-1]
8081
if c == "\n":
8182
result_found = False
8283
result = result[len(MIXED_CORTEX_MARKER) : -len(MIXED_CORTEX_MARKER)]
@@ -96,6 +97,9 @@ def run_cli(
9697
return result
9798
return output
9899

100+
if result != "":
101+
raise CortexBinaryException(result + "\n" + process.stderr.read())
102+
99103
raise CortexBinaryException(process.stderr.read())
100104

101105

0 commit comments

Comments
 (0)