Finally! Easy Error Handling

I finally found a systematic way of handling simple errors, with anyhow crate! :grinning:
Using:

.context(...)?;
.with_context(|| lazyfunction(...))?;

 return Err(anyhow!(...)); 
2 Likes

You can replace

return Err(anyhow!(...));

with

bail!(...)
2 Likes

I am wondering if I could use the lazyfunction within .with_context() for a simple "in place" error recovery.

For example, when an http connection fails, I just want to sleep for a few seconds and then try again just once more.

This seems much simpler than having to create a special type of error for it, return it, then test for it at a calling function, then call this one again, keeping a count of the tries. Or is my idea "unidiomatic"? Any opinions on this?