Explain invocation presentation failures

This commit is contained in:
2026-10-26 14:28:58 +00:00
parent 215fc34d51
commit 13a4d4eacd
7 changed files with 96 additions and 13 deletions

View File

@@ -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