Comments (5)
Could you show exactly what you would want this chain of errors to be printed as?
from anyhow.
In this example error, lowest level is (4) https://github.com/rust-embedded/svd/blob/27beb89c3eef5fbc8640b1655444a92be2888aa4/src/error.rs#L16 and I think it should be printed by Display
All other strings were added by with_context
.
In peripheral PLIC
- highest level of context.
Although I may be wrong.
from anyhow.
If it is generally accepted I close issue.
from anyhow.
I think this is behaving correctly. For example in standard library errors you can see the lowest level underlying error is not what is printed as the main representation:
use std::ffi::CString;
use std::error::Error;
fn main() {
let cstring = CString::new(vec![255]).unwrap();
let error = cstring.into_string().unwrap_err();
println!("DISPLAY: {}", error);
println!("CAUSE: {}", error.source().unwrap());
}
DISPLAY: C string contained non-utf8 bytes
CAUSE: invalid utf-8 sequence of 1 bytes from index 0
The lowest level error is "invalid utf-8 sequence of 1 bytes from index 0" while the context is "C string contained non-utf8 bytes".
If you want the cause chain printed in the opposite order, you can try printing it yourself:
use anyhow::anyhow;
fn main() {
let err = anyhow!("Expected content in <enumeratedValues> tag, found none")
.context("In field `priority`")
.context("Parsing field #0")
.context("In register `threshold`")
.context("In cluster `targets[%s]`")
.context("In peripheral `PLIC`");
for err in err.chain().rev() {
println!("{}", err);
}
}
But I would recommend instead phrasing your contexts to make it more clear what failed:
Error: Invalid data for peripheral `PLIC` in STM32F30x.svd
Caused by:
0: Failed to load cluster `targets[%s]` from svd
1: Failed to load register `threshold` from svd
2: Failed to parse field #0 of register
3: Invalid value for field `priority`
4: Expected content in <enumeratedValues> tag, found none
from anyhow.
I think this is behaving correctly. For example in standard library errors you can see the lowest level underlying error is not what is printed as the main representation:
Thank you for explanation.
from anyhow.
Related Issues (20)
- A way to disable anyhow stacktraces (without disabling stacktraces from other crates) HOT 2
- Default Ok-type to `()` in `anyhow::Result` typedef HOT 2
- Updating from version 1.0.76 breaks backtraces HOT 2
- Make backtrace support optional HOT 10
- Possible performance regression on Windows HOT 5
- as_ref() type must be known at this point
- Depending on `CARGO_ENCODED_RUSTFLAGS` may produce stale builds HOT 1
- rust-analyzer nightly throws needless_return warning on bail! HOT 2
- Implement Context for Error
- Question regarding stacktrace
- anyhow::Error to Box<dyn Error> isn't compatible with other libraries HOT 2
- Are you open to de-duplicating the build.rs build probe code? HOT 7
- `anyhow::ensure!` doesn't work with custom error type HOT 1
- Short backtrace HOT 2
- Feature suggestion: ensure_some!() for unwrapping options HOT 3
- Cannot compile when using `ensure!` HOT 1
- Unsound usages of unsafe implementation from `u8` to `str` HOT 2
- Conversion to Box<dyn Error> loses downcast ability
- This library almost disables multithreading while used with `RUST_BACKTRACE=1`
- Add a programmable switch for backtrace
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anyhow.