Skip to content

fix: exit 1 on provider errors in non-interactive mode #834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading