Skip to content

Commit 9f403e0

Browse files
Vasko Mitanovvaskomitanov
Vasko Mitanov
authored andcommitted
Print server side messages, if sent by the RE
1 parent b91a610 commit 9f403e0

File tree

9 files changed

+80
-12
lines changed

9 files changed

+80
-12
lines changed

app/buck2_build_api/src/actions/calculation.rs

+41-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use buck2_build_signals::NodeDuration;
2121
use buck2_common::events::HasEvents;
2222
use buck2_core::base_deferred_key::BaseDeferredKey;
2323
use buck2_core::target::configured_target_label::ConfiguredTargetLabel;
24-
use buck2_data::ActionErrorDiagnostics;
24+
use buck2_data::{action_error_diagnostics, ActionErrorDiagnostics};
2525
use buck2_data::ActionSubErrors;
2626
use buck2_data::ToProtoMessage;
2727
use buck2_events::dispatch::async_record_root_spans;
@@ -57,6 +57,7 @@ use crate::actions::error_handler::ActionSubErrorResult;
5757
use crate::actions::error_handler::StarlarkActionErrorContext;
5858
use crate::actions::execute::action_executor::ActionOutputs;
5959
use crate::actions::execute::action_executor::HasActionExecutor;
60+
use crate::actions::execute::error::ExecuteError;
6061
use crate::actions::RegisteredAction;
6162
use crate::artifact_groups::calculation::ensure_artifact_group_staged;
6263
use crate::deferred::calculation::lookup_deferred_holder;
@@ -255,7 +256,8 @@ async fn build_action_no_redirect(
255256

256257
let last_command = commands.last().cloned();
257258

258-
let error_diagnostics = try_run_error_handler(action.dupe(), last_command.as_ref());
259+
let origin_error_diagnostics = try_run_error_handler(action.dupe(), last_command.as_ref());
260+
let error_diagnostics = build_error_diagnostics(&e, origin_error_diagnostics);
259261

260262
let e = ActionError::new(
261263
e,
@@ -357,10 +359,46 @@ async fn build_action_no_redirect(
357359
},
358360
spans,
359361
})?;
360-
361362
action_execution_data.action_result
362363
}
363364

365+
fn build_error_diagnostics(execute_error: &ExecuteError, error_diagnostics: Option<ActionErrorDiagnostics>) -> Option<ActionErrorDiagnostics> {
366+
let ExecuteError::CommandExecutionError { error: Some(command_execute_error) } = execute_error else {
367+
return error_diagnostics;
368+
};
369+
let action_sub_error = || buck2_data::ActionSubError {
370+
category: "ServerMessage".to_string(),
371+
message: Some(format!("{}", command_execute_error)),
372+
locations: None,
373+
};
374+
if let Some(inner_error_diagnostics) = &error_diagnostics {
375+
if let Some(error_diagnostics_data) = &inner_error_diagnostics.data {
376+
match error_diagnostics_data {
377+
action_error_diagnostics::Data::SubErrors(action_sub_errors) => {
378+
let mut sub_errors = action_sub_errors.sub_errors.clone();
379+
sub_errors.push(action_sub_error());
380+
Some(ActionErrorDiagnostics {
381+
data: Some(action_error_diagnostics::Data::SubErrors(ActionSubErrors { sub_errors })),
382+
})
383+
},
384+
action_error_diagnostics::Data::HandlerInvocationError(handler_error) => {
385+
Some(ActionErrorDiagnostics {
386+
data: Some(action_error_diagnostics::Data::HandlerInvocationError(format!("{}\n{}", handler_error, command_execute_error))),
387+
})
388+
},
389+
}
390+
} else {
391+
Some(ActionErrorDiagnostics {
392+
data: Some(action_error_diagnostics::Data::SubErrors(ActionSubErrors { sub_errors: vec![action_sub_error()] })),
393+
})
394+
}
395+
} else {
396+
Some(ActionErrorDiagnostics {
397+
data: Some(action_error_diagnostics::Data::SubErrors(ActionSubErrors { sub_errors: vec![action_sub_error()] })),
398+
})
399+
}
400+
}
401+
364402
// Attempt to run the error handler if one was specified. Returns either the error diagnostics, or
365403
// an actual error if the handler failed to run successfully.
366404
fn try_run_error_handler(

app/buck2_build_api/src/actions/error.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
use std::fmt;
11-
1211
use buck2_event_observer::display::display_action_error;
1312
use buck2_event_observer::display::TargetDisplayOptions;
1413

app/buck2_build_api/src/actions/execute/action_executor.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,15 @@ impl ActionExecutionCtx for BuckActionExecutionContext<'_> {
462462
error: Some(error.clone()),
463463
})
464464
}
465-
_ => Err(ExecuteError::CommandExecutionError { error: None }),
465+
_ => {
466+
#[derive(Display, Debug, thiserror::Error)]
467+
struct ServerError {
468+
message: String,
469+
}
470+
Err(ExecuteError::CommandExecutionError { error: result.server_message.map(|server_message| buck2_error::Error::new(ServerError{
471+
message: server_message,
472+
})) })
473+
},
466474
};
467475
self.command_reports.extend(rejected_execution);
468476
self.command_reports.push(report);

app/buck2_client_ctx/src/subscribers/superconsole.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::time::Duration;
1515

1616
use anyhow::Context as _;
1717
use async_trait::async_trait;
18-
use buck2_data::CommandExecutionDetails;
18+
use buck2_data::{action_error_diagnostics, ActionError, CommandExecutionDetails};
1919
use buck2_event_observer::display;
2020
use buck2_event_observer::display::display_file_watcher_end;
2121
use buck2_event_observer::display::TargetDisplayOptions;
@@ -621,7 +621,7 @@ impl StatefulSuperConsoleImpl {
621621
async fn handle_action_error(&mut self, error: &buck2_data::ActionError) -> anyhow::Result<()> {
622622
let mut lines = vec![];
623623
let display_platform = self.state.config.display_platform;
624-
624+
Self::write_diagnostics(&error, &mut lines);
625625
let display::ActionErrorDisplay {
626626
action_id,
627627
reason,
@@ -650,12 +650,31 @@ impl StatefulSuperConsoleImpl {
650650
if let Some(command) = command {
651651
lines_for_command_details(&command, self.verbosity, &mut lines);
652652
}
653-
654653
self.super_console.emit(Lines(lines));
655-
656654
Ok(())
657655
}
658656

657+
fn write_diagnostics(error: &&ActionError, lines: &mut Vec<Line>) {
658+
if let Some(error_diagnostics) = &error.error_diagnostics {
659+
if let Some(data) = &error_diagnostics.data {
660+
if let action_error_diagnostics::Data::SubErrors(action_sub_errors) = &data {
661+
for sub_error in &action_sub_errors.sub_errors {
662+
if let Some(message) = &sub_error.message {
663+
let action_diag = StyledContent::new(
664+
ContentStyle {
665+
foreground_color: Some(Color::Yellow),
666+
..Default::default()
667+
},
668+
format!("{}: {:?}", sub_error.category, message),
669+
);
670+
lines.push(Line::from_iter([Span::new_styled_lossy(action_diag)]));
671+
}
672+
}
673+
}
674+
}
675+
}
676+
}
677+
659678
async fn handle_test_result(&mut self, result: &buck2_data::TestResult) -> anyhow::Result<()> {
660679
if let Some(msg) = display::format_test_result(result)? {
661680
self.super_console.emit(msg);

app/buck2_execute/src/execute/manager.rs

+2
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ impl CommandExecutionManagerLike for CommandExecutionManager {
143143
eligible_for_full_hybrid: false,
144144
dep_file_metadata: None,
145145
action_result: None,
146+
server_message: None,
146147
}
147148
}
148149

@@ -223,6 +224,7 @@ impl CommandExecutionManagerLike for CommandExecutionManagerWithClaim {
223224
eligible_for_full_hybrid: false,
224225
dep_file_metadata: None,
225226
action_result: None,
227+
server_message: None,
226228
}
227229
}
228230

app/buck2_execute/src/execute/result.rs

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ pub struct CommandExecutionResult {
196196
/// to be re-used when uploading the remote dep file.
197197
#[derivative(Debug = "ignore")]
198198
pub action_result: Option<TActionResult2>,
199+
pub server_message: Option<String>,
199200
}
200201

201202
impl CommandExecutionResult {

app/buck2_execute_impl/src/executors/re.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ impl ReExecutor {
189189
platform: platform.clone(),
190190
remote_dep_file_key: None,
191191
};
192-
193192
let execution_kind = response.execution_kind(remote_details);
194193
let manager = manager.with_execution_kind(execution_kind.clone());
194+
195195
if response.status.code != TCode::OK {
196196
let res = if let Some(out) = as_missing_outputs_error(&response.status) {
197197
// TODO: Add a dedicated report variant for this.
@@ -236,7 +236,6 @@ impl ReExecutor {
236236
error_type,
237237
)
238238
};
239-
240239
return ControlFlow::Break(res);
241240
}
242241

@@ -357,9 +356,9 @@ impl PreparedCommandExecutor for ReExecutor {
357356
)
358357
.boxed()
359358
.await;
360-
361359
let DownloadResult::Result(mut res) = res;
362360
res.action_result = Some(response.action_result);
361+
res.server_message = if response.message.is_empty() { None } else { Some(response.message) };
363362
res
364363
}
365364

remote_execution/oss/re_grpc/src/client.rs

+1
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ impl REClient {
664664
},
665665
cached_result: execute_response_grpc.cached_result,
666666
action_digest: Default::default(), // Filled in below.
667+
message: execute_response_grpc.message,
667668
};
668669

669670
ExecuteWithProgressResponse {

remote_execution/oss/re_grpc/src/response.rs

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ pub struct ExecuteResponse {
176176
pub action_digest: TDigest,
177177
pub action_result_digest: TDigest,
178178
pub action_result_ttl: i64,
179+
pub message: String,
179180
}
180181

181182
#[derive(Clone, Default)]

0 commit comments

Comments
 (0)