jam1garner / binrw

A Rust crate for helping parse and rebuild binary data using ✨macro magic✨.
https://binrw.rs
MIT License
585 stars 35 forks source link

Design BinRead backtrace output #56

Closed jam1garner closed 3 years ago

jam1garner commented 3 years ago

Here is a possible mockup:

image

Raw text minus ansi escape sequences:

 ╺━━━━━━━━━━━━━━━━━━━━┅ Backtrace ┅━━━━━━━━━━━━━━━━━━━━╸

 0: Reader reached the end of the file
     at src/entry.rs:100
  ┄───╮
   98 │  #[br(big)]
   99 │  #[br(calc = index_count)]
  100 ⎬╴ indices: Vec<u32>,
  ┄───╯

 1: While parsing field 'entries' in FileHeader
     at src/file_header.rs:6
  ┄───╮
    5 │  #[br(big, calc = entry_count + 1)]
    6 ⎬╴ entries: Vec<Entry>,
  ┄───╯

 2: While parsing field 'header' in MyFile
     at src/my_file.rs:15
  ┄───╮  
      │  #[br(little)]
   12 │  struct MyFile {
      …
   15 ⎬╴     header: FileHeader,
  ┄───╯

 ╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸

(Excuse github's mono font having horrible box drawing character support, any sane terminal won't have this issue)

And here is what condensed mode will look like:

 0: Reader reached the end of the file
     at src/entry.rs:100
 1: While parsing field 'entries' in FileHeader
     at src/file_header.rs:6
 2: While parsing field 'header' in MyFile
     at src/my_file.rs:15
csnover commented 3 years ago

Some things that came to mind immediately to think about were: (1) ensure field name is always in the failure message itself, (2) rendering where multiple fields are on one line in the source, (3) being able to see the contents of related variables, (4) being able to see where the stream started the read and failed the read.

Also FWIW my workflow is going to be either receiving a report from an end user (so wanting only compact output) or just clicking on the source of the failure to view it in the IDE so don’t expect to derive much personal benefit from flashy output.

vivlim commented 3 years ago

I haven't used it myself, but it might be worth taking a look at miette which seems like it would do a bunch of heavy lifting with respect to actually formatting things.

example: screenshot of miette