Skip to content

Commit aefad8a

Browse files
committed
catch measureme panics and log errors
1 parent 01467a4 commit aefad8a

File tree

1 file changed

+21
-6
lines changed
  • collector/src/compile/execute

1 file changed

+21
-6
lines changed

collector/src/compile/execute/mod.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -636,12 +636,27 @@ fn parse_self_profile(
636636
let (profile, files) = if let Some(profile_path) = full_path {
637637
// measureme 0.8+ uses a single file
638638
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+
645660
let profile = SelfProfile {
646661
artifact_sizes: results.artifact_sizes,
647662
};

0 commit comments

Comments
 (0)