Skip to content

Commit ac6fe53

Browse files
VeykrilLukas Wirth
andauthored
Capture execution backtrace when throwing UnexpectedCycle (#883)
Co-authored-by: Lukas Wirth <[email protected]>
1 parent 79c2eac commit ac6fe53

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/cycle.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,18 @@ use crate::sync::OnceLock;
6262
/// Should only be relevant in case of a badly configured cycle recovery.
6363
pub const MAX_ITERATIONS: IterationCount = IterationCount(200);
6464

65-
pub struct UnexpectedCycle(Option<crate::Backtrace>);
66-
67-
impl fmt::Debug for UnexpectedCycle {
68-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69-
f.write_str("cycle detected but no cycle handler found")?;
70-
if let Some(backtrace) = &self.0 {
71-
f.write_str(": ")?;
72-
backtrace.fmt(f)?;
73-
}
74-
Ok(())
75-
}
65+
pub struct UnexpectedCycle {
66+
backtrace: std::backtrace::Backtrace,
67+
query_trace: Option<crate::Backtrace>,
7668
}
7769

7870
impl fmt::Display for UnexpectedCycle {
7971
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80-
f.write_str("cycle detected but no cycle handler found")?;
81-
if let Some(backtrace) = &self.0 {
72+
f.write_str("cycle detected but no cycle handler found\n")?;
73+
self.backtrace.fmt(f)?;
74+
if let Some(query_trace) = &self.query_trace {
8275
f.write_str("\n")?;
83-
backtrace.fmt(f)?;
76+
query_trace.fmt(f)?;
8477
}
8578
Ok(())
8679
}
@@ -89,8 +82,11 @@ impl fmt::Display for UnexpectedCycle {
8982
impl UnexpectedCycle {
9083
pub(crate) fn throw() -> ! {
9184
// We use resume and not panic here to avoid running the panic
92-
// hook (that is, to avoid collecting and printing backtrace).
93-
panic::resume_unwind(Box::new(Self(crate::Backtrace::capture())));
85+
// hook (that is to avoid printing the backtrace).
86+
panic::resume_unwind(Box::new(Self {
87+
backtrace: std::backtrace::Backtrace::capture(),
88+
query_trace: crate::Backtrace::capture(),
89+
}));
9490
}
9591

9692
/// Runs `f`, and catches any salsa cycle.

0 commit comments

Comments
 (0)