dirs-rs icon indicating copy to clipboard operation
dirs-rs copied to clipboard

Add better descriptions as to what causes None to be returned.

Open Peter-Lande opened this issue 3 years ago • 9 comments

Currently the documentation is vague about what causes None returns in functions. It would be very helpful to be able to not have to comb through the code to implement the api calls and know what is happening if None is returned.

Peter-Lande avatar Sep 23 '22 22:09 Peter-Lande

Regards this, could you provide more information on the nature of what is to be returned

opeolluwa avatar Apr 01 '23 07:04 opeolluwa

If you indulge me, I could return a struct, which will contain the PathBuf if any, and an error message if none

opeolluwa avatar Apr 01 '23 08:04 opeolluwa

Like a Result?

soc avatar Apr 01 '23 16:04 soc

A result that returns the Ok(Pathbuf) or an Err(Strong)

opeolluwa avatar Apr 01 '23 16:04 opeolluwa

Yeah I think that is a better solution that the current Some/None strategy. Having some way to understand what failed to happen is better than it failing with no context. I am not entirely sure what the original context was of this issue, let me review the code I used that faced this issue and get back to you.

Peter-Lande avatar Apr 01 '23 17:04 Peter-Lande

I looked it up, I think it's coming from the dir-sys crate

opeolluwa avatar Apr 01 '23 17:04 opeolluwa

The main concern when I thought about this pre-1.0 was that the errors that may show up in the failure case are hard to predict/test/standardize across platforms.

soc avatar Apr 01 '23 18:04 soc

Hmmm 🤔

opeolluwa avatar Apr 01 '23 18:04 opeolluwa

Now, the challenge is getting the error cause, which would be better than a generic message I suggested earlier

opeolluwa avatar Apr 01 '23 18:04 opeolluwa