3 ms·
There is not (normally) context added automatically. One can use `map_err(|e| ...)` to add context like this: let result = call().map_err(|e| SomeError::Mo
by codys 4y ago
There is not (normally) context added automatically. One can use `map_err(|e| ...)` to add context like this:
let result = call().map_err(|e| SomeError::MoreData(e))?;
Or if using one of the common error libraries to have non-specific error kinds:
let result = call().context("some data")?;
or
let result = call().with_context(format!("something happened: {}", other_thing))?;
For something that more directly matches the behavior of the go code, this (using the `anyhow` crate) is a possible match:
let result = call().map_err(|e| anyhow::Error::msg(format!("Error while trying to call: {:?}", e)?;
Though one would normally avoid this when using anyhow (or in rust in general) as it means we're flattening the error instead of generating a list of causes.