-
Notifications
You must be signed in to change notification settings - Fork 667
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
No conversion between Errno and std::io::Error/i32 #613
Comments
There is |
I'm sure I looked for that but couldn't find it in the documentation! I now realize that it wouldn't be in the documentation at all (rust-lang/rust#42440). In any case, this is not sufficient because errno doesn't store the original error code, so unknown codes get clobberred into |
Okay, I think I understand the issue here. You want the Right now there is |
There are two separate issues.
#[test]
fn errno_conversion() {
assert_eq!(std::io::Error::from(nix::Errno::from_i32(1234)).raw_os_error(), Some(1234));
}
|
Regarding the first point, I definitely agree. I think we would be better served to move all error handing into an As for the second point, that behavior is because |
@jethrogb Would you be willing to add some docs to the errno module explaining this conversion? As to your second point, I don't think we need to support arbitrary |
By “that function” do you mean Errno's do occasionally change Newly introduced error codes might not make much sense to old binaries interpreting them, but at least they can mean something to the user (either in raw form or through strerror by dynamically linking to libc). It seems like a waste to throw away this valuable error information. |
@jethrogb I'd be happy to consider a more concrete solution here along if it also showed specific use cases the current system doesn't allow or are ergonomic. Please file a PR if you have an idea for what you want and think is reasonable to implement and we can iterate there I think. |
Here's a related issue that doesn't work right now fn io_func() -> io::Result<()> {
std::fs::some_function()?;
nix::some_other_function()?;
} |
@kahing That shouldn't work. Not all error types are compatible between libraries, nor are they designed to be compatible. There is no appropriate mapping that works in all use cases from In your code example, you should invent a new error type that provides a @jethrogb Are you interested in filing a PR and driving a resolution for this issue? |
I understand that they are not compatible but since rust io and nix are often used together, it would be nice if they were compatible out of the box. (yes, I do have my own error type now). |
I think it makes a lot of sense to provide I'll look into doing a PR at some point |
@jethrogb we removed it in #614, we won't be adding it back in, so need to work on a PR for this. The rust-y way to handle this is to create your own error type and map from all other errors into that error type for export. @jethrogb If you want to file a PR for the other things we've discussed in this issue, that would definitely be considered. |
I would love to see Reasoning: People are writing their own conversions. @paulpr0 is doing it in the reference above, and I will be doing it too. Having a good impl in nix would reduce friction for users who want to manage errors in this way. Would the existence of |
I'm using Lines 77 to 86 in a4a465d
But, in fact, there's absolutely no need for that The error conversion would then simply be done via What I'm saying is that current API for I propose reviewing the code to find all places where using |
I think this now served by |
@ExceptionallyHandsome #613 (comment)
|
There will likely be an |
Also, I'd like to make a case for why that impl should be added again: |
Due to nix ways to handle errors, errno is a big enum instead of an i32, and due to nix-rust/nix#613 we must do our own error handling anyway.
There are situation where you want to have the raw error value of an error, e.g. for passing back into C code. Also, there is already a perfectly good type for holding errno in Rust,
std::io::Error
. It does support getting the raw error value. I suggest deprecatingErrno
in favor ofstd::io::Error
or at least adding the necessary conversions.The text was updated successfully, but these errors were encountered: