Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export reproc's status code constants in C++ binding #74

Open
HellsingDarge opened this issue Nov 21, 2021 · 7 comments
Open

Export reproc's status code constants in C++ binding #74

HellsingDarge opened this issue Nov 21, 2021 · 7 comments

Comments

@HellsingDarge
Copy link

std::error_code (to which reproc++ maps in its methods) produces C++-defined error codes only for POSIX, making it impossible to check against them without using #if OS code

@DaanDeMeyer
Copy link
Owner

I don't understand. We simply store whatever error that was returned by the OS in the error code. All major standard library implementations define a mapping that allows comparing against these system specific errors using the generic constants from https://en.cppreference.com/w/cpp/error/errc.

If this doesn't work, please post a code example that reproduces the issue and I'll look into it

@HellsingDarge
Copy link
Author

From the page you've linked:

The scoped enumeration std::errc defines the values of portable error conditions that correspond to the POSIX error codes.

On Windows (WAIT_TIMEOUT = 258L):

spdlog::info(std::errc::timed_out == std::error_code { 138, std::system_category() });              // false
spdlog::info(std::errc::timed_out == std::error_code {-REPROC_ETIMEDOUT, std::system_category() }); // false
spdlog::info(std::errc::timed_out == std::error_code { WAIT_TIMEOUT, std::system_category() });     // false

spdlog::info(std::errc::timed_out == std::error_code { 138, std::generic_category() });              // true
spdlog::info(std::errc::timed_out == std::error_code {-REPROC_ETIMEDOUT, std::generic_category() }); // false
spdlog::info(std::errc::timed_out == std::error_code { WAIT_TIMEOUT, std::generic_category() });     // false

spdlog::info(std::make_error_condition(std::errc::timed_out) == std::error_code { 138, std::system_category() });              // false
spdlog::info(std::make_error_condition(std::errc::timed_out) == std::error_code {-REPROC_ETIMEDOUT, std::system_category() }); // false
spdlog::info(std::make_error_condition(std::errc::timed_out) == std::error_code { WAIT_TIMEOUT, std::system_category() });     // false

spdlog::info(std::make_error_condition(std::errc::timed_out) == std::error_code { 138, std::generic_category() });              // true
spdlog::info(std::make_error_condition(std::errc::timed_out) == std::error_code {-REPROC_ETIMEDOUT, std::generic_category() }); // false
spdlog::info(std::make_error_condition(std::errc::timed_out) == std::error_code { WAIT_TIMEOUT, std::generic_category() });     // false

@DaanDeMeyer
Copy link
Owner

I could have sworn MSVC's stdlib defined a mapping to allow comparing the system errors against the portable constants as well. I'll dig into the stdlib implementation when I find some time since it's been a while since I last looked at this.

@DaanDeMeyer
Copy link
Owner

I opened microsoft/STL#2572 against the STL. Let's see what they have to say.

@HellsingDarge
Copy link
Author

I used timed_out as an example (since it's the one I've first encountered this problem on), so it may also affect other error codes

@DaanDeMeyer
Copy link
Owner

There's likely more indeed, but I'm starting with this one to see if they're receptive to modifying the mapping at all since technically changing this in the stdlib is a compat break so they might not want to change it. If that's the case we'll need to figure out something in reproc itself.

@DaanDeMeyer
Copy link
Owner

It seems they're interested in fixing this in stdlib but they don't do it in every release. If you encounter any more of these missing matches, I'd report them in that STL issue I linked so they can add extra matches for those as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants