@@ -21,7 +21,7 @@ use buck2_build_signals::NodeDuration;
21
21
use buck2_common:: events:: HasEvents ;
22
22
use buck2_core:: base_deferred_key:: BaseDeferredKey ;
23
23
use buck2_core:: target:: configured_target_label:: ConfiguredTargetLabel ;
24
- use buck2_data:: ActionErrorDiagnostics ;
24
+ use buck2_data:: { action_error_diagnostics , ActionErrorDiagnostics } ;
25
25
use buck2_data:: ActionSubErrors ;
26
26
use buck2_data:: ToProtoMessage ;
27
27
use buck2_events:: dispatch:: async_record_root_spans;
@@ -57,6 +57,7 @@ use crate::actions::error_handler::ActionSubErrorResult;
57
57
use crate :: actions:: error_handler:: StarlarkActionErrorContext ;
58
58
use crate :: actions:: execute:: action_executor:: ActionOutputs ;
59
59
use crate :: actions:: execute:: action_executor:: HasActionExecutor ;
60
+ use crate :: actions:: execute:: error:: ExecuteError ;
60
61
use crate :: actions:: RegisteredAction ;
61
62
use crate :: artifact_groups:: calculation:: ensure_artifact_group_staged;
62
63
use crate :: deferred:: calculation:: lookup_deferred_holder;
@@ -255,7 +256,8 @@ async fn build_action_no_redirect(
255
256
256
257
let last_command = commands. last ( ) . cloned ( ) ;
257
258
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) ;
259
261
260
262
let e = ActionError :: new (
261
263
e,
@@ -357,10 +359,46 @@ async fn build_action_no_redirect(
357
359
} ,
358
360
spans,
359
361
} ) ?;
360
-
361
362
action_execution_data. action_result
362
363
}
363
364
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
+
364
402
// Attempt to run the error handler if one was specified. Returns either the error diagnostics, or
365
403
// an actual error if the handler failed to run successfully.
366
404
fn try_run_error_handler (
0 commit comments