File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -391,18 +391,28 @@ async fn try_with_maybe_muted_stderr<R>(
391391 verbose : bool ,
392392 f : impl Future < Output = anyhow:: Result < R > > ,
393393) -> anyhow:: Result < R > {
394+ use std:: io:: { Seek , SeekFrom } ;
395+ use std:: sync:: Arc ;
394396 if verbose {
395397 f. await
396398 } else {
397399 let stderr = stderr ( ) . lock ( ) ;
398400 let stderr_fd = nix:: unistd:: dup ( & stderr) . context ( "failed to dup stderr" ) ?;
401+ let stderr_fd = Arc :: new ( stderr_fd) ;
399402 let logfile = NamedTempFile :: new ( ) . context ( "failed to create temporary logfile" ) ?;
400403 nix:: unistd:: dup2_stderr ( logfile. as_file ( ) ) . context ( "failed to mute stderr" ) ?;
404+ let hook = std:: panic:: take_hook ( ) ;
405+ std:: panic:: set_hook ( Box :: new ( {
406+ let stderr_fd = Arc :: clone ( & stderr_fd) ;
407+ move |panic_info| {
408+ let _ = nix:: unistd:: dup2_stderr ( & stderr_fd) ;
409+ hook ( panic_info) ;
410+ }
411+ } ) ) ;
401412 let result = f. await ;
413+ _ = std:: panic:: take_hook ( ) ;
402414 nix:: unistd:: dup2_stderr ( & stderr_fd) . context ( "failed to restore stderr" ) ?;
403415 if result. is_err ( ) {
404- use std:: io:: { Seek , SeekFrom } ;
405-
406416 let mut log_contents = String :: new ( ) ;
407417 let logfile_read_result = logfile
408418 . as_file ( )
You can’t perform that action at this time.
0 commit comments