Explain invocation presentation failures
This commit is contained in:
35
reporter.go
35
reporter.go
@@ -281,6 +281,9 @@ func (r *Reporter) finalize(outcome Outcome, completion func(*Reporter)) Outcome
|
||||
|
||||
state.mu.Lock()
|
||||
if presentationFailedLocked(state) {
|
||||
if outcome.Status == 0 && !hasExplanation(outcome.Explanation) {
|
||||
outcome.Explanation.Message = presentationFailureMessage(state)
|
||||
}
|
||||
outcome = applyPresentationFailure(outcome)
|
||||
}
|
||||
if outcome.Status != 0 {
|
||||
@@ -328,18 +331,38 @@ func applyPresentationFailure(outcome Outcome) Outcome {
|
||||
}
|
||||
|
||||
func ensureFallbackExplanation(outcome Outcome) Outcome {
|
||||
if outcome.Explanation.Message != "" {
|
||||
if hasExplanation(outcome.Explanation) {
|
||||
return outcome
|
||||
}
|
||||
for _, detail := range outcome.Explanation.Details {
|
||||
if detail != nil {
|
||||
return outcome
|
||||
}
|
||||
}
|
||||
outcome.Explanation = Explanation{Message: "Command failed."}
|
||||
return outcome
|
||||
}
|
||||
|
||||
func hasExplanation(explanation Explanation) bool {
|
||||
if explanation.Message != "" {
|
||||
return true
|
||||
}
|
||||
for _, detail := range explanation.Details {
|
||||
if detail != nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func presentationFailureMessage(state *reportingState) string {
|
||||
switch {
|
||||
case state.output.renderError != nil:
|
||||
return "Unable to render command output."
|
||||
case state.output.writeError != nil:
|
||||
return "Unable to deliver command output."
|
||||
case state.diagnostics.renderError != nil:
|
||||
return "Unable to render invocation diagnostics."
|
||||
default:
|
||||
return "Unable to deliver invocation diagnostics."
|
||||
}
|
||||
}
|
||||
|
||||
func renderTerminalLocked(state *reportingState, explanation Explanation) error {
|
||||
destination := state.destination(destinationDiagnostics)
|
||||
destination.submitted = true
|
||||
|
||||
Reference in New Issue
Block a user