When printing message in non-interactive mode, do not keep printing out the worst diagnostic. (#1640)

This commit is contained in:
CyrusNajmabadi 2018-07-17 13:00:10 -07:00 committed by GitHub
parent 4e43dec05c
commit 2e9a2e8a91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 12 deletions

View file

@ -63,8 +63,14 @@ func makeActionProgress(id string, action string) Progress {
type DiagInfo struct { type DiagInfo struct {
ErrorCount, WarningCount, InfoCount, DebugCount int ErrorCount, WarningCount, InfoCount, DebugCount int
// The last event of each severity kind. We'll print out the most significant of these next // The very last diagnostic event we got for this resource (regardless of severity). We'll print
// to a resource while it is in progress. // this out in the non-interactive mode whenever we get new events. Importantly, we don't want
// to print out the most significant diagnostic, as that means a flurry of event swill cause us
// to keep printing out the most significant diagnostic over and over again.
LastDiag *engine.DiagEventPayload
// The last event of each severity kind. We'll print out the most significant of these (in the
// tree-view) next to a resource while it is in progress.
LastError, LastWarning, LastInfoError, LastInfo, LastDebug *engine.DiagEventPayload LastError, LastWarning, LastInfoError, LastInfo, LastDebug *engine.DiagEventPayload
// All the diagnostic events we've heard about this resource. We'll print the last diagnostic // All the diagnostic events we've heard about this resource. We'll print the last diagnostic

View file

@ -194,6 +194,8 @@ func (data *resourceRowData) RecordDiagEvent(event engine.Event) {
diagInfo := data.diagInfo diagInfo := data.diagInfo
payload := event.Payload.(engine.DiagEventPayload) payload := event.Payload.(engine.DiagEventPayload)
diagInfo.LastDiag = &payload
switch payload.Severity { switch payload.Severity {
case diag.Error: case diag.Error:
diagInfo.LastError = &payload diagInfo.LastError = &payload
@ -286,11 +288,11 @@ func (data *resourceRowData) ColorizedColumns() []string {
columns[statusColumn] = data.display.getStepInProgressDescription(step) columns[statusColumn] = data.display.getStepInProgressDescription(step)
} }
columns[infoColumn] = data.getInfo() columns[infoColumn] = data.getInfoColumn()
return columns return columns
} }
func (data *resourceRowData) getInfo() string { func (data *resourceRowData) getInfoColumn() string {
step := data.step step := data.step
changesBuf := &bytes.Buffer{} changesBuf := &bytes.Buffer{}
@ -354,14 +356,28 @@ func (data *resourceRowData) getInfo() string {
appendDiagMessage(fmt.Sprintf("%v debug messages", diagInfo.DebugCount)) appendDiagMessage(fmt.Sprintf("%v debug messages", diagInfo.DebugCount))
} }
// If we're not totally done, also print out the worst diagnostic next to the status message. if !data.display.Done {
// This is helpful for long running tasks to know what's going on. However, once done, we print // If we're not totally done, and we're in the tree-view also print out the worst diagnostic
// the diagnostics at the bottom, so we don't need to show this. // next to the status message. This is helpful for long running tasks to know what's going
worstDiag := getWorstDiagnostic(data.diagInfo) // on. However, once done, we print the diagnostics at the bottom, so we don't need to show
if worstDiag != nil && !data.display.Done { // this.
eventMsg := data.display.renderProgressDiagEvent(*worstDiag, true /*includePrefix:*/) //
if eventMsg != "" { // if we're not in the tree-view (i.e. non-interactive mode), then we want to print out
diagMsg += ". " + eventMsg // whatever the last diagnostics was that we got. This way, as we're hearing about
// diagnostic events, we're always printing out the last one.
var diagnostic *engine.DiagEventPayload
if data.display.isTerminal {
diagnostic = data.diagInfo.LastDiag
} else {
diagnostic = getWorstDiagnostic(data.diagInfo)
}
if diagnostic != nil {
eventMsg := data.display.renderProgressDiagEvent(*diagnostic, true /*includePrefix:*/)
if eventMsg != "" {
diagMsg += ". " + eventMsg
}
} }
} }