dtolnay/anyhow

Support for constructing an error with a cause and a message

DanielBauman88 opened this issue · 2 comments

Anyhow supports a macro to construct an anyhow error from a source error or an anyhow error from a string.

There isn't a way to create an error with a cause and a message.

There have been many occasions where anyhow would be a very handy way for me to wrap a library error but where I want to add some context as the message.

EG: I write some simple code where I want to wrap all library errors in an anyhow error but where I sometimes want to add a helpful context message which will be shown when the higher level caller logs the anyhow error message (along with the cause-chain and the backtrace).

Is there a way to do this today with anyhow? Could be that I just missed it.
If there isn't, is this something you'd be in favour of supporting?

anyhow::Error::new(cause).context(message)

Thanks! Missed that!
I see now that the main docs page does show how it can be done with the with_context method on Result, and that is super handy too.