Flexible concrete Rust Error type built on `std::error::Error`. The library provides `anyhow::Error`, a trait object based error type for easy idiomatic error handling in Rust applications.
Questions tagged [anyhow]
9 questions
22
votes
3 answers
Mixing anyhow::Result with std::io::Result
Can anyone help me understand why this code compiles fine:
use actix_web::{App, HttpServer};
use anyhow::Result;
mod error;
#[actix_rt::main]
async fn main() -> Result<()> {
HttpServer::new(|| App::new())
.bind("127.0.0.1:8080")?
…

Zizheng Tai
- 6,170
- 28
- 79
8
votes
1 answer
Why is anyhow not working in the stable version?
I have a clean project to which I include anyhow 1.0.66.
Installed the latest version of rust.
I'm getting an error saying that anyhow requires a nightly version. Perhaps this is due to the use of backtrace, but it is supported in rust version 1.65.…

Genius Merely
- 374
- 2
- 11
4
votes
2 answers
Rust test - how fail verbosely if Result object is not Ok?
My use case is pretty simple - if an actual object is not an Ok variant, I would like this test to fail explicitly by showing what it contains instead:
fn test_foo() {
let actual = fn_that_returns_result();
// not verbose enough in case it is…

BinaryButterfly
- 18,137
- 13
- 50
- 91
2
votes
2 answers
How to make a method returning XMLError compatible with anyhow::Error?
This is my code (XMLElement from xml-builder):
use anyhow::Result;
use xml_builder::XMLElement;
fn foo() -> Result<()> {
let mut v = XMLElement::new("v");
v.add_child(XMLElement::new("e"))?;
Ok(())
}
It doesn't compile:
error[E0277]: the…

yegor256
- 102,010
- 123
- 446
- 597
2
votes
0 answers
Nom errors over bytes dont actually implement Error
I am building a pretty simple parser over &[u8]. Unfortunately, when I try to convert the errors I get into anyhow errors, it informs me that the various nom Error types (nom::error::Error and nom::error::VerboseError) don't implement Display, and…

kazagistar
- 1,537
- 8
- 20
2
votes
2 answers
Error handling for applications: how to return a public message error instead of all the chain of errors and tracing it at the same time?
PROLOGUE
I'm using async-graphql and I have hundreds of resolvers and for each resolver I would like to trace all the possible errors.
In each method of my app I'm using anyhow::{Error}.
Right now I have code similar to this for each…

Fred Hors
- 3,258
- 3
- 25
- 71
1
vote
1 answer
Returning anyhow::Result in service actix-web
I am trying to use anyhow::Result instead of std::io::Result in an actix-web service. This is because I want to be able to use the "?" operator instead of .expect/.map_err. However, I am getting an error message:
error[E0277]: `?` couldn't convert…

VenoX
- 11
- 2
1
vote
1 answer
Getting the anyhow Rust crate to format an error like it does when when exiting the main function
Adding the anyhow crate to a blank Rust project and running the following code gives you the output Error: error, which I want:
use anyhow::anyhow;
fn error() -> anyhow::Result<()> {
Err(anyhow!("error"))
}
fn main() -> anyhow::Result<()> {
…

weisbrja
- 164
- 10
0
votes
1 answer
In Rust, How do I go about ensuring convertibility of types to std::error:Error throught traits when the types implement from()?
quite new to rust and trying to find myself around traits - I am working on a custom testing module and am trying to construct Result types where the Err is of a TestIssue enum that either implements an Error or Failure. I essentially want any Error…

Skorpius
- 2,135
- 2
- 26
- 31