Anyhow: is it possible to append context?

When I use anyhow's .with_context(|| error_text) the only text that appears is error_text with the original error text gone. Is it possible to append extra error text?

eyre?

anyhow supports several different output formats, documented here. {:#} concatenates all of the messages together, and {:?} shows them in multiline format.

Here is anyhow!("error").context("inner context").context("outer context") formatted four ways:

{} — Display

outer context

{:#} — Display alternate

outer context: inner context: error

{:?} — Debug

outer context

Caused by:
    0: inner context
    1: error

{:#?} — Debug alternate

Error {
    context: "outer context",
    source: Error {
        context: "inner context",
        source: "error",
    },
}

Playground

11 Likes

Thank you very much: the "{:#}" format is exactly what it needed.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.