MortalreminderPT / edit-xlsx

A quick and easy-to-use Rust library for Excel file editing.
https://crates.io/crates/edit-xlsx
16 stars 4 forks source link

Can't decode "WorkbookError" #16

Open mschnell1 opened 2 months ago

mschnell1 commented 2 months ago

As it is in the resultsmodule, which is private.

I simply want to decently print the "file not found error" by

            let e_text = match e {
                edit_xlsx::result::WorkbookError::FileNotFound  => "File not Found: ".to_owned() + &format!("{:?}", in_file_name),
                _ => format!("{:?}", e),
            };
MortalreminderPT commented 2 months ago

The fact is that Error is not very functional right now. I was going to refactor it after I finished the documentation, but that's been put on hold for a number of reasons

mschnell1 commented 2 months ago

@MortalreminderPT I perfectly get a "File Not Found" error with Workbook::from_path(in_file_name) I can display it correctly decoded by format!("{:?}", e) with e from the result, and hence a WorkbookError.

 error: "Io(Os { code: 2, kind: NotFound, message: \"Das System kann die angegebene Datei nicht finden.\" })

I in fact don't understand how the debug print functionality can get that information to be displayed from the private error type. In the end I would like to just do Workbook::from_path(in_file_name)?;, but the result type of my function is std::io::Errror and this is not compiled as no converter function is found.

MortalreminderPT commented 1 month ago

I implemented it in a new commit, you can see the way to convert a custom Error by clicking here 😊

mschnell1 commented 1 month ago

Sorry, but I still can't find out how to usethe word WorkbookError ( defined in results.rs) in my code. That is why I cant compile your snippet.

If I do use edit_xlsx::WorkbookError; I get noWorkbookErrorin the root

mschnell1 commented 1 month ago

@MortalreminderPT

Ooops. Now trying to cargo clean and recompile I get

  --> C:\Users\mschnell\.cargo\registry\src\index.crates.io-6f17d22bba15001f\edit-xlsx-0.4.4\src\result.rs:35:5
   |
34 |     ColError(ColError),result
   |                              -
   |                              |
   |                              expected one of `(`, `,`, `=`, `{`, or `}`
   |                              help: missing `,`
35 |     DuplicatedSheets,
   |     ^^^^^^^^^^^^^^^^ unexpected token
MortalreminderPT commented 1 month ago

@MortalreminderPT

Ooops. Now trying to cargo clean and recompile I get

  --> C:\Users\mschnell\.cargo\registry\src\index.crates.io-6f17d22bba15001f\edit-xlsx-0.4.4\src\result.rs:35:5
   |
34 |     ColError(ColError),result
   |                              -
   |                              |
   |                              expected one of `(`, `,`, `=`, `{`, or `}`
   |                              help: missing `,`
35 |     DuplicatedSheets,
   |     ^^^^^^^^^^^^^^^^ unexpected token

I may have misunderstood your intention, can you give me more information, like your code snippets, which could help me understand your needs better.

mschnell1 commented 1 month ago

Something seems to have gone wrong with downloading the edit-xlsx code. I did another clean an compile and now it works. The erroneous word resultis gone now. Sorry for trouble :(

mschnell1 commented 1 month ago

Nonetheless I can't do (copied from your example)

#[derive(Debug)]
use std::num::ParseIntError;
use edit_xlsx::{Workbook, WorkbookResult, WorkbookError};
enum MyError {
    ParseIntError(ParseIntError),
    WorkbookError(WorkbookError),
}

I get:

21 | use edit_xlsx::{Workbook, WorkbookResult, WorkbookError};
   |                                           ^^^^^^^^^^^^^ no `WorkbookError` in the root
mschnell1 commented 1 month ago

Here a draft of the code I'd like to implement in my project:


                       let e_text = match e {
                           edit_xlsx::result::WorkbookError::FileNotFound  => "File not Found: ".to_owned() + 
                                          &format!("{:?}", in_file_name),
                           _ => format!("{:?}", e),
                       };
  `` 
mschnell1 commented 1 month ago

Workbook::from_path(in_file_name)?;

would be an even better option, if a conversion from WorkbookError into std::io::Error would be provided.

mschnell1 commented 1 month ago

simply adding pub use result::WorkbookError; to src/lib.rs does the trick (temporarily)

It then compiles, but other than hoped, if the file does not exist, the WorkbookError::FileNotFound is not issued, but WorkbookError::Io.

mschnell1 commented 1 month ago

Sorry, testing all I can imagine, I can't do what is done in the here link given above.