From 520934dc7a2f3167f05f78f975da8a0fb68f66e0 Mon Sep 17 00:00:00 2001 From: Tyler Beebe Date: Tue, 17 Nov 2026 21:39:03 +0000 Subject: [PATCH] fix(cli): say why an upload failed An upload error with a base message ("There was an unexpected error that occurred while uploading test results") printed only Trunk's explanation beneath it, so an error with none, such as --allow-forked-pr-uploads outside a fork pull request, printed a blank line where the reason belongs, in the summary and in the GitHub annotation alike. Print the error and its causes in that case. Co-Authored-By: Claude Opus 5.5 --- cli/src/summary_output/error.rs | 11 +++++++++++ cli/src/summary_output/github.rs | 2 +- cli/src/summary_output/text.rs | 6 ++---- cli/tests/summary/error_report.rs | 27 +++++++++++++++++++++++++++ cli/tests/summary/github.rs | 16 ++++++++++++++++ 5 files changed, 57 insertions(+), 5 deletions(-) diff --git a/cli/src/summary_output/error.rs b/cli/src/summary_output/error.rs index 09338204..17600b03 100644 --- a/cli/src/summary_output/error.rs +++ b/cli/src/summary_output/error.rs @@ -43,4 +43,15 @@ impl ErrorSummary { exit_code: context.exit_code, } } + + /// What went wrong, for a reader who already has `message`: Trunk's explanation when its API + /// gave one, else the error with its causes. + pub fn reason(&self) -> String { + self.explanation.clone().unwrap_or_else(|| { + std::iter::once(self.error.as_str()) + .chain(self.causes.iter().map(String::as_str)) + .collect::>() + .join(": ") + }) + } } diff --git a/cli/src/summary_output/github.rs b/cli/src/summary_output/github.rs index b10d4be1..28d25aa6 100644 --- a/cli/src/summary_output/github.rs +++ b/cli/src/summary_output/github.rs @@ -182,7 +182,7 @@ fn error_message(error: &ErrorSummary) -> String { match &error.message { Some(message) => { lines.push(message.clone()); - lines.extend(error.explanation.clone()); + lines.push(error.reason()); } None => lines.push(error.error.clone()), } diff --git a/cli/src/summary_output/text.rs b/cli/src/summary_output/text.rs index f5d3ce0b..2fd8ada1 100644 --- a/cli/src/summary_output/text.rs +++ b/cli/src/summary_output/text.rs @@ -138,10 +138,8 @@ pub fn render_error(error: &ErrorSummary) -> anyhow::Result> { if let Some(message) = &error.message { lines.push(Line::from_iter([Span::new_unstyled_lossy(message)])); lines.push(Line::default()); - if let Some(explanation) = &error.explanation { - lines.push(Line::from_iter([Span::new_unstyled_lossy(explanation)])); - lines.push(Line::default()); - } + lines.push(Line::from_iter([Span::new_unstyled_lossy(error.reason())])); + lines.push(Line::default()); } else { lines.push(Line::from_iter([Span::new_unstyled_lossy(&error.error)])); } diff --git a/cli/tests/summary/error_report.rs b/cli/tests/summary/error_report.rs index 87922bec..f5741052 100644 --- a/cli/tests/summary/error_report.rs +++ b/cli/tests/summary/error_report.rs @@ -55,6 +55,33 @@ fn prints_a_client_error_explanation_beneath_the_base_message() { ); } +#[test] +fn prints_the_error_and_its_causes_beneath_the_base_message() { + let error = anyhow::anyhow!( + "--allow-forked-pr-uploads without a Trunk API token uploads only from a GitHub Actions run of a pull request from a fork; test results will not be uploaded." + ) + .context("Failed to create bundle upload"); + let report = ErrorReport::new( + error, + String::from("fake-org-slug"), + Some(String::from("There was an unexpected error")), + ); + + assert_eq!( + error_summary(&report), + [ + "Error Encountered", + "There was an unexpected error", + "", + "Failed to create bundle upload: --allow-forked-pr-uploads without a Trunk API token uploads only from a GitHub Actions run of a pull request from a fork; test results will not be uploaded.", + "", + "For more help, contact us at https://slack.trunk.io/", + "", + "Errors occurred during execution, using quarantining exit code", + ] + ); +} + #[test] fn prints_connection_refused_beneath_the_base_message() { let report = ErrorReport::new( diff --git a/cli/tests/summary/github.rs b/cli/tests/summary/github.rs index 3508072c..12eb7e1f 100644 --- a/cli/tests/summary/github.rs +++ b/cli/tests/summary/github.rs @@ -233,6 +233,22 @@ fn warns_about_an_upload_error_before_the_failures() { ); } +#[test] +fn warns_with_the_reason_an_upload_failed() { + let mut result = upload_result(3); + result.error_report = Some(ErrorReport::new( + anyhow::anyhow!("uploads only from a pull request from a fork") + .context("Failed to create bundle upload"), + String::from("test-org"), + Some(String::from(UPLOAD_ERROR_MESSAGE)), + )); + + assert_eq!( + upload_annotations(&result)[0], + "::warning::There was an unexpected error that occurred while uploading test results%0AFailed to create bundle upload: uploads only from a pull request from a fork", + ); +} + #[test] fn warns_that_results_with_old_timestamps_will_be_dropped() { let mut result = upload_result(5);