local-ip-address icon indicating copy to clipboard operation
local-ip-address copied to clipboard

Use Os Error

Open bigdogs opened this issue 2 years ago • 5 comments

hi,

Checked the reported error on getifaddrs failed, https://github.com/EstebanBorai/local-ip-address/blob/main/src/macos.rs#L38

I think it's more reasonable to return the specific os error from std::io::Error::last_os_error()

bigdogs avatar Apr 12 '22 06:04 bigdogs

Hi @bigdogs!

I see last_os_error may provide more details on the error in question.

For the current implementation, and to have backwards compatibility, I think we could use that to fill Error::StrategyError with the corresponding error message, what do you think?

LeoBorai avatar Apr 12 '22 22:04 LeoBorai

Hi, @EstebanBorai

thiserror can wrap an error type, I think we can add a new enum item for std io error

    #[error("some description here...")]
    IOError(#[from] std::io::Error),

Coverting last_os_error to message is OK if user doesn't care about the error detail.

bigdogs avatar Apr 13 '22 00:04 bigdogs

Hi, @EstebanBorai

thiserror can wrap an error type, I think we can add a new enum item for std io error


    #[error("some description here...")]

    IOError(#[from] std::io::Error),

Coverting last_os_error to message is OK if user doesn't care about the error detail.

Sounds good. We could add a new item but Im afraid users would have to check on more enums making error handling a bit harder.

Perhaps we could draft a new release where the StrategyError variant provides a native OS error with all the details (the one you refer to here).

Its important that we keep in mind that the same abstraction on the error must be provided to every supported platform (macOS, Linux and Windows).

To do so, I suggest we have a trait which is implemented to each of these OS errors and retrieves details using functions, similar to how diesel handles database errors for different engines.

How do you see this?

LeoBorai avatar Apr 13 '22 12:04 LeoBorai

Sounds good to me 👍

bigdogs avatar Apr 13 '22 12:04 bigdogs

Sounds good to me 👍

If you are interested on working on this, please don't hesitate on opening a PR I'm happy to help whenever I can!

LeoBorai avatar Apr 15 '22 17:04 LeoBorai