Add logging feature#271
Merged
Merged
Conversation
* 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
Owner
|
LGTM thanks! I think this format from @hawkw could be really cool for debugging: https://twitter.com/mycoliza/status/1529987746269233152/photo/2 |
sharksforarms
approved these changes
Jul 4, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
context to the Err values from deku parsers by adding logging from the
log crate.
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.
This could be expanded in the future to enums and/or other internal deku
structs.
Even cooler would be something like this:
See #168