@@ -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 ("\n Result: %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 ("\n Stack 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