Skip to content

Commit 9c56463

Browse files
authored
fix: exit 1 on provider errors in non-interactive mode (#834)
1 parent 16c85cb commit 9c56463

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cmd/stack.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,13 @@ var stackUpdateCmd = &cobra.Command{
307307

308308
// Step 5b. Communicate with server to share progress of ...
309309
if isNonInteractive() {
310+
providerErrorDetected := false
311+
310312
fmt.Printf("Deploying %s stack with provider %s\n", stackConfig.Name, stackConfig.Provider)
311313
go func() {
312314
for update := range errorChan {
313315
fmt.Printf("Error: %s\n", update)
316+
providerErrorDetected = true
314317
}
315318
}()
316319

@@ -348,6 +351,11 @@ var stackUpdateCmd = &cobra.Command{
348351
fmt.Printf("\nResult: %s\n", content.Result.GetText())
349352
}
350353
}
354+
355+
// ensure the process exits with a non-zero status code after all messages are processed
356+
if providerErrorDetected {
357+
os.Exit(1)
358+
}
351359
} else {
352360
// interactive environment
353361
// Step 5c. Start the stack up view
@@ -491,10 +499,13 @@ nitric stack down -s aws -y`,
491499
})
492500

493501
if isNonInteractive() {
502+
providerErrorDetected := false
503+
494504
fmt.Printf("Deploying %s stack with provider %s\n", stackConfig.Name, stackConfig.Provider)
495505
go func() {
496506
for update := range errorChan {
497507
fmt.Printf("Error: %s\n", update)
508+
providerErrorDetected = true
498509
}
499510
}()
500511

@@ -532,6 +543,11 @@ nitric stack down -s aws -y`,
532543
fmt.Println("\nStack down complete")
533544
}
534545
}
546+
547+
// ensure the process exits with a non-zero status code after all messages are processed
548+
if providerErrorDetected {
549+
os.Exit(1)
550+
}
535551
} else {
536552
stackDown := stack_down.New(stackConfig.Provider, stackConfig.Name, eventChannel, providerStdout, errorChan)
537553

0 commit comments

Comments
 (0)