mullvad / windows-service-rs

Windows services in Rust
Apache License 2.0
525 stars 85 forks source link

Add `Error.is_os_error` #89

Closed citreae535 closed 1 year ago

citreae535 commented 1 year ago

This function checks if an error from win32 API call matches a specific OS error code. This makes it easier for users to check specific API errors.


This change is Reviewable

faern commented 1 year ago

I'm not against this PR. But I also want to note that this crate is supposed to be a high level abstraction for Windows services, and a user of the library should preferably not need to deal with OS error codes or other windows-sys stuff if possible.

citreae535 commented 1 year ago

Hmm, I reconsidered it and have to agree that most users won't need this change. Better close it then.

pronebird commented 1 year ago

Currently we do not translate errors returned from syscalls into meaningful errors. Instead we return Winapi(io::Error) variant so the one has to parse io::Error to find the cause of error.

We could of course introduce new error types and provide error variants for common error codes but we would almost always have to have a Other(io::Error) variant since we do not control Windows API. I am not quite sure that beefing up a single Error type would be the way to go, on the other side having dedicated errors types would mean that we'd have to have duplicate error variants like those that we currently have in the Error type.

Anyhow, reinventing that would be a big task.