Skip to content

error-stack: Why does error_stack::Report::frames() produce a breadth-first iterator? #2758

Closed Answered by indietyp
mkatychev asked this question in Help (Libraries)
Discussion options

You must be logged in to vote

Sure! Sorry for the long wait. I kind of forgot to answer 😅

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 mut report = Report::new(CAttachment);
	report.extend_one(Report::new(DAttachment).attach_printable("E"));
	
    let report = report
        .change_context(AError)
        .attach_printable("B");

    for frame in report.frames() {
        println!("{frame:?}");
    }
    println!();
    Err(report)
}

This should fix the problem (notice the …

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
1 reply
@indietyp
Comment options

Comment options

You must be logged in to vote
5 replies
@indietyp
Comment options

@TimDiekmann
Comment options

@mkatychev
Comment options

@indietyp
Comment options

indietyp Sep 4, 2023
Collaborator

Answer selected by mkatychev
@mkatychev
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/libs > error-stack Affects the `error-stack` crate (library) area/libs Relates to first-party libraries/crates/packages (area)
3 participants