Open Nicceboy opened 1 year ago
Thank you for your issue! I agree we should have a good pretty print.
I think the ambition should be Rust's error's, it should be immediately obvious, the error should not be noisy.
There's likely an error formatting library we can take advantage of.
I think part of this should be that we trim the backtrace by default to show like three lines, ideally not from the libraries or rasn, and to have a method for the full backtrace.
For conditional full backtrace, I was thinking either direct --cfg
flags for compiler or env
variables ( like RUST_LIB_BACKTRACE
or RUST_BACKTRACE
), since it is mostly useful for developers which relies on and compiles the library and less likely needed for-end users (at least now), which do not compile the library.
Since the library supports #![no_std]
, env
variables should be added with build scripts.
If someone wants to get full backtraces on embedded systems without recompilation, they can be warned that add it on compile time for now.
I guess making it as encoder/decoder option is alternative too, maybe later.
That's a good point about no_std, I think my preference would be a cargo feature rather than cfg, because that's more intuitive to use than cfg variables.
I think the "warning" would be included in the backtrace, similar to how RUST_BACKTRACE
works.
We might need to format the overall errors. Should we just convert it pretty-printed
json
(oncejer
is merged), or make custom formatter? It is a bit better now after thefield_error
change, but maybe it could be made cleaner.Here is a decode error for around 7 nested structures...
Might need to think about that backtrace, if we could only show the deepest one.
Expand error
```console thread 'tests::test_bsm_with_cert' panicked at ieee1609dot2/src/lib.rs:767:9: called `Result::unwrap()` on an `Err` value: DecodeError { kind: FieldError { name: "Ieee1609Dot2Data.content", nested: DecodeError { kind: FieldError { name: "SignedData.signer", nested: DecodeError { kind: FieldError { name: "CertificateBase.to_be_signed", nested: DecodeError { kind: FieldError { name: "ToBeSignedCertificate.validity_period", nested: DecodeError { kind: FieldError { name: "ValidityPeriod.duration", nested: DecodeError { kind: CodecSpecific { inner: Oer(InvalidTagVariantOnChoice { value: Tag { class: Application, value: 23 }, is_extensible: false }) }, codec: Oer, backtrace: Backtrace( 0: backtrace::backtrace::libunwind::trace at /Users/nicce/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.68/src/backtrace/libunwind.rs:93:5 backtrace::backtrace::trace_unsynchronized at /Users/nicce/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.68/src/backtrace/mod.rs:66:5 1: backtrace::backtrace::trace at /Users/nicce/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.68/src/backtrace/mod.rs:53:14 2: backtrace::capture::Backtrace::create at /Users/nicce/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.68/src/capture.rs:176:9 3: backtrace::capture::Backtrace::new at /Users/nicce/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.68/src/capture.rs:140:22 4: