error-stack: Why does error_stack::Report::frames()
produce a breadth-first iterator?
#2758
-
Given the rust code below: use error_stack::Report;
#[derive(Debug, thiserror::Error)]
#[error("A")]
pub struct AError;
#[derive(Debug, thiserror::Error)]
#[error("C")]
pub struct CAttachment;
#[derive(Debug, thiserror::Error)]
#[error("D")]
pub struct DAttachment;
fn main() -> Result<(), Report<AError>> {
let report = Report::new(CAttachment)
.attach_printable(Report::new(DAttachment).attach_printable("E"))
.change_context(AError)
.attach_printable("B");
for frame in report.frames() {
println!("{frame:?}");
}
println!();
Err(report)
} The output below is given:
Why does the
While calling
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
This looks like a bug to me, cc @indietyp. Thank you for reporting this! |
Beta Was this translation helpful? Give feedback.
-
Okay, I think I have an answer, this is quite peculiar, but basically what's happening is that you're constructing: let report = Report::new(CAttachment)
.attach_printable(Report::new(DAttachment).attach_printable("E"))
.change_context(AError)
.attach_printable("B"); leads to the following tree:
So the output will be:
|
Beta Was this translation helpful? Give feedback.
Sure! Sorry for the long wait. I kind of forgot to answer 😅
This should fix the problem (notice the …