Skip to content

Commit

Permalink
fix: exit 1 on provider errors in non-interactive mode (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
davemooreuws authored Dec 18, 2024
1 parent 16c85cb commit 9c56463
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cmd/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,13 @@ var stackUpdateCmd = &cobra.Command{

// Step 5b. Communicate with server to share progress of ...
if isNonInteractive() {
providerErrorDetected := false

fmt.Printf("Deploying %s stack with provider %s\n", stackConfig.Name, stackConfig.Provider)
go func() {
for update := range errorChan {
fmt.Printf("Error: %s\n", update)
providerErrorDetected = true
}
}()

Expand Down Expand Up @@ -348,6 +351,11 @@ var stackUpdateCmd = &cobra.Command{
fmt.Printf("\nResult: %s\n", content.Result.GetText())
}
}

// ensure the process exits with a non-zero status code after all messages are processed
if providerErrorDetected {
os.Exit(1)
}
} else {
// interactive environment
// Step 5c. Start the stack up view
Expand Down Expand Up @@ -491,10 +499,13 @@ nitric stack down -s aws -y`,
})

if isNonInteractive() {
providerErrorDetected := false

fmt.Printf("Deploying %s stack with provider %s\n", stackConfig.Name, stackConfig.Provider)
go func() {
for update := range errorChan {
fmt.Printf("Error: %s\n", update)
providerErrorDetected = true
}
}()

Expand Down Expand Up @@ -532,6 +543,11 @@ nitric stack down -s aws -y`,
fmt.Println("\nStack down complete")
}
}

// ensure the process exits with a non-zero status code after all messages are processed
if providerErrorDetected {
os.Exit(1)
}
} else {
stackDown := stack_down.New(stackConfig.Provider, stackConfig.Name, eventChannel, providerStdout, errorChan)

Expand Down

0 comments on commit 9c56463

Please sign in to comment.