tmontaigu / dbase-rs

Rust library to read & write dBase files.
MIT License
29 stars 30 forks source link

assertion error #43

Open rpodgorny opened 2 years ago

rpodgorny commented 2 years ago

hi, i'm trying to write a dbf file (from another dbf) and i keep failing with the following traceback:

thread 'main' panicked at 'assertion failed: `(left == right)`                                                                                              
  left: `7`,                                                                                                                                                                                   
 right: `6`': /home/radek/.cargo/registry/src/github.com-1ecc6299db9ec823/dbase-0.3.0/src/writing.rs:365                                                                                       
   0: <backtrace::capture::Backtrace as core::default::Default>::default                                                                                                                       
             at /home/radek/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.66/src/capture.rs:410:9                                                                              
   1: log_panics::Config::install_panic_hook::{{closure}}                                                                                                                                      
             at /home/radek/.cargo/registry/src/github.com-1ecc6299db9ec823/log-panics-2.1.0/src/lib.rs:115:29                                                                                 
   2: std::panicking::rust_panic_with_hook
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:702:17
   3: std::panicking::begin_panic_handler::{{closure}}
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:588:13
   4: std::sys_common::backtrace::__rust_end_short_backtrace
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/sys_common/backtrace.rs:138:18
   5: rust_begin_unwind
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:584:5
   6: core::panicking::panic_fmt
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panicking.rs:142:14
   7: core::panicking::assert_failed_inner
   8: core::panicking::assert_failed
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panicking.rs:181:5
   9: dbase::writing::FieldWriter<W>::write_next_field_value
             at /home/radek/.cargo/registry/src/github.com-1ecc6299db9ec823/dbase-0.3.0/src/writing.rs:365:13
  10: <dbase::reading::Record as dbase::writing::WritableRecord>::write_using
             at /home/radek/.cargo/registry/src/github.com-1ecc6299db9ec823/dbase-0.3.0/src/writing.rs:306:13
  11: dbase::writing::TableWriter<W>::write_record
             at /home/radek/.cargo/registry/src/github.com-1ecc6299db9ec823/dbase-0.3.0/src/writing.rs:488:9
  12: dbase::writing::TableWriter<W>::write_records
             at /home/radek/.cargo/registry/src/github.com-1ecc6299db9ec823/dbase-0.3.0/src/writing.rs:544:13
  13: mj191_tool::main
             at src/main.rs:80:5

(...it goes on but that's not interesting, i guess)

the code is basically this:

let mut reader = dbase::Reader::from_path(db_fn).unwrap();                                                                                             
let mut recs = reader.read().unwrap();                                                                      
let mut writer = dbase::TableWriterBuilder::from_reader(reader).build_with_file_dest("/tmp/test.dbf").unwrap();
writer.write_records(&recs).unwrap();

...what could be the cause?

thanks!

tmontaigu commented 2 years ago

Seems like its this debug_assert that is being hit https://github.com/tmontaigu/dbase-rs/blob/b731e63b5fae3f4e451d7206beb55e6304009f60/src/writing.rs#L365

Since its a debug assert it should not be possible to trigger it in release mode (cargo run --release), can you try to run your program in release mode and see if the generated file is still valid ?

The assert seems a bit restrictive, what you may see in the output file is some truncated values