@@ -1056,11 +1056,29 @@ Executed at: {executed_at}"#,
1056
1056
}
1057
1057
} ;
1058
1058
1059
- let fail = |message : & str | {
1059
+ let fail = |message : & str , output : CommandOutput | -> ! {
1060
1060
if self . is_verbose ( ) {
1061
1061
println ! ( "{message}" ) ;
1062
1062
} else {
1063
- println ! ( "Command has failed. Rerun with -v to see more details." ) ;
1063
+ let ( stdout, stderr) = ( output. stdout_if_present ( ) , output. stderr_if_present ( ) ) ;
1064
+ // If the command captures output, the user would not see any indication that
1065
+ // it has failed. In this case, print a more verbose error, since to provide more
1066
+ // context.
1067
+ if stdout. is_some ( ) || stderr. is_some ( ) {
1068
+ if let Some ( stdout) =
1069
+ output. stdout_if_present ( ) . take_if ( |s| !s. trim ( ) . is_empty ( ) )
1070
+ {
1071
+ println ! ( "STDOUT:\n {stdout}\n " ) ;
1072
+ }
1073
+ if let Some ( stderr) =
1074
+ output. stderr_if_present ( ) . take_if ( |s| !s. trim ( ) . is_empty ( ) )
1075
+ {
1076
+ println ! ( "STDERR:\n {stderr}\n " ) ;
1077
+ }
1078
+ println ! ( "Command {command:?} has failed. Rerun with -v to see more details." ) ;
1079
+ } else {
1080
+ println ! ( "Command has failed. Rerun with -v to see more details." ) ;
1081
+ }
1064
1082
}
1065
1083
exit ! ( 1 ) ;
1066
1084
} ;
@@ -1069,14 +1087,14 @@ Executed at: {executed_at}"#,
1069
1087
match command. failure_behavior {
1070
1088
BehaviorOnFailure :: DelayFail => {
1071
1089
if self . fail_fast {
1072
- fail ( & message) ;
1090
+ fail ( & message, output ) ;
1073
1091
}
1074
1092
1075
1093
let mut failures = self . delayed_failures . borrow_mut ( ) ;
1076
1094
failures. push ( message) ;
1077
1095
}
1078
1096
BehaviorOnFailure :: Exit => {
1079
- fail ( & message) ;
1097
+ fail ( & message, output ) ;
1080
1098
}
1081
1099
BehaviorOnFailure :: Ignore => {
1082
1100
// If failures are allowed, either the error has been printed already
0 commit comments