Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improve ease of debugging an incorrect parser implementation by adding context to the Err values from deku parsers by adding logging from the log crate. * This is feature-gated under the new "logging" feature. From the following sample program, you can easily see the improved error message and debugging since we known the field that was incorrect parsed. Much easier than gdb. ``` [dependencies] deku = { path = "../deku", features = ["logging"]} log = "0.4.17" env_logger = "0.9.0" ``` ``` use deku::prelude::*; pub struct TestStruct { pub a: u16, pub b: u16, } fn main() { env_logger::init(); TestStruct::from_bytes((&[0x01, 0x02, 0x03], 0)).unwrap(); println!("Hello, world!"); } ``` ``` > RUST_LOG=trace cargo r Finished dev [unoptimized + debuginfo] target(s) in 0.27s Running `target/debug/deku-testing` [2022-07-04T16:11:54Z TRACE deku_testing] Reading: TestStruct::a from [00000001, 00000010, 00000011] [2022-07-04T16:11:54Z TRACE deku_testing] Reading: TestStruct::b from [00000011] thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Incomplete(NeedSize { bits: 16 })', src/main.rs:11:54 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` This could be expanded in the future to enums and/or other internal deku structs. See sharksforarms#168
- Loading branch information