Merge pull request #7913 from hashicorp/red_herring_EOF_abort
[WIP] Red herring eof abort
This commit is contained in:
commit
7ac17126a0
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -71,17 +70,9 @@ func (s abortStep) Run(ctx context.Context, state multistep.StateBag) multistep.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s abortStep) Cleanup(state multistep.StateBag) {
|
func (s abortStep) Cleanup(state multistep.StateBag) {
|
||||||
err, ok := state.GetOk("error")
|
shouldCleanup := handleAbortsAndInterupts(state, s.ui, typeName(s.step))
|
||||||
if ok {
|
if !shouldCleanup {
|
||||||
s.ui.Error(fmt.Sprintf("%s", err))
|
return
|
||||||
}
|
|
||||||
if _, ok := state.GetOk(multistep.StateCancelled); ok {
|
|
||||||
s.ui.Error("Interrupted, aborting...")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
if _, ok := state.GetOk(multistep.StateHalted); ok {
|
|
||||||
s.ui.Error(fmt.Sprintf("Step %q failed, aborting...", typeName(s.step)))
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
s.step.Cleanup(state)
|
s.step.Cleanup(state)
|
||||||
}
|
}
|
||||||
|
@ -112,7 +103,8 @@ func (s askStep) Run(ctx context.Context, state multistep.StateBag) (action mult
|
||||||
case askCleanup:
|
case askCleanup:
|
||||||
return
|
return
|
||||||
case askAbort:
|
case askAbort:
|
||||||
os.Exit(1)
|
state.Put("aborted", true)
|
||||||
|
return
|
||||||
case askRetry:
|
case askRetry:
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -120,6 +112,12 @@ func (s askStep) Run(ctx context.Context, state multistep.StateBag) (action mult
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s askStep) Cleanup(state multistep.StateBag) {
|
func (s askStep) Cleanup(state multistep.StateBag) {
|
||||||
|
if _, ok := state.GetOk("aborted"); ok {
|
||||||
|
shouldCleanup := handleAbortsAndInterupts(state, s.ui, typeName(s.step))
|
||||||
|
if !shouldCleanup {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
s.step.Cleanup(state)
|
s.step.Cleanup(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,3 +168,33 @@ func askPrompt(ui packer.Ui) askResponse {
|
||||||
ui.Say(fmt.Sprintf("Incorrect input: %#v", line))
|
ui.Say(fmt.Sprintf("Incorrect input: %#v", line))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleAbortsAndInterupts(state multistep.StateBag, ui packer.Ui, stepName string) bool {
|
||||||
|
// if returns false, don't run cleanup. If true, do run cleanup.
|
||||||
|
_, alreadyLogged := state.GetOk("abort_step_logged")
|
||||||
|
|
||||||
|
err, ok := state.GetOk("error")
|
||||||
|
if ok && !alreadyLogged {
|
||||||
|
ui.Error(fmt.Sprintf("%s", err))
|
||||||
|
state.Put("abort_step_logged", true)
|
||||||
|
}
|
||||||
|
if _, ok := state.GetOk(multistep.StateCancelled); ok {
|
||||||
|
if !alreadyLogged {
|
||||||
|
ui.Error("Interrupted, aborting...")
|
||||||
|
state.Put("abort_step_logged", true)
|
||||||
|
} else {
|
||||||
|
ui.Error(fmt.Sprintf("aborted: skipping cleanup of step %q", stepName))
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if _, ok := state.GetOk(multistep.StateHalted); ok {
|
||||||
|
if !alreadyLogged {
|
||||||
|
ui.Error(fmt.Sprintf("Step %q failed, aborting...", stepName))
|
||||||
|
state.Put("abort_step_logged", true)
|
||||||
|
} else {
|
||||||
|
ui.Error(fmt.Sprintf("aborted: skipping cleanup of step %q", stepName))
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
3
log.go
3
log.go
|
@ -35,6 +35,9 @@ func logOutput() (logOutput io.Writer, err error) {
|
||||||
if strings.Contains(scanner.Text(), "ui:") {
|
if strings.Contains(scanner.Text(), "ui:") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if strings.Contains(scanner.Text(), "ui error:") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
os.Stderr.WriteString(fmt.Sprint(scanner.Text() + "\n"))
|
os.Stderr.WriteString(fmt.Sprint(scanner.Text() + "\n"))
|
||||||
}
|
}
|
||||||
}(scanner)
|
}(scanner)
|
||||||
|
|
Loading…
Reference in New Issue