jmcnamara / rust_xlsxwriter

A Rust library for creating Excel XLSX files.
https://crates.io/crates/rust_xlsxwriter
Apache License 2.0
335 stars 26 forks source link

Looking for feedback on rust_xlsxwriter error handling #14

Closed jmcnamara closed 1 year ago

jmcnamara commented 1 year ago

Request for Feedback

Currently the rust_xlsxwriter error generation and handling is a bit restrictive. For background the error conditions are listed in the XlsxError docs: https://docs.rs/rust_xlsxwriter/latest/rust_xlsxwriter/enum.XlsxError.html

There are 2 levels of error that can affect an Excel file:

I am looking for feedback from people using the library on their experience with the APIs and error handling.

jmbrunskill commented 1 year ago

I've only just started using this library, and haven't got experience with the C, or Python versions of the library. However, in general I support returning errors for dataloss situations. I think rust programmers generally expect robustness and would rather know the constraints and allow accurate reporting of data issues etc.

I can see the use case for still being able to create a valid file even with some dataloss though.

As inspiration, you could have a look at what chrono has done? They have two versions of a lot of functions one that returns an option and one that just panics (they're actually in the process of phase this out but still...)

https://docs.rs/chrono/latest/chrono/naive/struct.NaiveDate.html#method.from_ymd https://docs.rs/chrono/latest/chrono/naive/struct.NaiveDate.html#method.from_ymd_opt

You could potentially do something similar with something like write_data_lossy which would not return and error, and have another version of the function write_data that does return an error?

jmcnamara commented 1 year ago

@jmbrunskill thanks for the feedback and suggestions.