@@ -636,12 +636,27 @@ fn parse_self_profile(
636
636
let ( profile, files) = if let Some ( profile_path) = full_path {
637
637
// measureme 0.8+ uses a single file
638
638
let data = fs:: read ( & profile_path) ?;
639
- let results = analyzeme:: ProfilingData :: from_paged_buffer ( data, None )
640
- . map_err ( |error| {
641
- eprintln ! ( "Cannot read self-profile data: {error:?}" ) ;
642
- std:: io:: Error :: new ( ErrorKind :: InvalidData , error)
643
- } ) ?
644
- . perform_analysis ( ) ;
639
+
640
+ // HACK: `decodeme` can unexpectedly panic on invalid data produced by rustc. We catch this
641
+ // here until it's fixed and emits a proper error.
642
+ let res =
643
+ std:: panic:: catch_unwind ( || analyzeme:: ProfilingData :: from_paged_buffer ( data, None ) ) ;
644
+ let results = match res {
645
+ Ok ( Ok ( profiling_data) ) => profiling_data. perform_analysis ( ) ,
646
+ Ok ( Err ( error) ) => {
647
+ // A "regular" error in measureme.
648
+ log:: error!( "Cannot read self-profile data: {error:?}" ) ;
649
+ return Err ( std:: io:: Error :: new ( ErrorKind :: InvalidData , error) ) ;
650
+ }
651
+ Err ( error) => {
652
+ // An unexpected panic in measureme: it sometimes happens when encountering some
653
+ // cases of invalid mm_profdata files.
654
+ let error = format ! ( "Unexpected measureme error with self-profile data: {error:?}" ) ;
655
+ log:: error!( "{error}" ) ;
656
+ return Err ( std:: io:: Error :: new ( ErrorKind :: InvalidData , error) ) ;
657
+ }
658
+ } ;
659
+
645
660
let profile = SelfProfile {
646
661
artifact_sizes : results. artifact_sizes ,
647
662
} ;
0 commit comments