-
Notifications
You must be signed in to change notification settings - Fork 182
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
Improve Error handling #54
Conversation
This change to the error type looks like it would interfere with |
I think we should not rush this decision and possibly postpone it. (ideally we would make this change together with dropping
What is rationale behind this change? |
Agreed, I put this change in this PR, but it really should be in a separate PR. My initial thought was to put all of the breaking changes together, but I think it makes sense for them to be split up.
My basic reasoning was that currently
I guess I'm surprised that @newpavlov I saw that you were against such a change in rust-random/rand#837 (adding an associated type). But if |
But you can retrieve I will answer regarding |
While this is possible, there's not a good way to actually go about doing it (as it's not clear what a user would even match on, or what types of values can be returned). This PR tries to address this by implementing There's also the bigger issue that certain implementations can't return a meaningful error code. |
Nothing forbids us from adding conversion to
While it's indeed may be a valid critique of the current implementation (though it also applies to the current std implementation as well). But it's not an argument in favor of your error type design.
But for most platforms you use |
b9cca59
to
84c5782
Compare
I agree with most of the above, as the changes I made here could be made with the old implementation. I've also updated this PR to make a few of those changes (specifically fixing Windows and iOS). Most the the efficiency arguments don't matter as long as If a user needs raw OS error codes, the current implementation allows that by converting to So @newpavlov what about a mix of what we've been talking about? Each target can still define the type of error that makes sense, essentially one of:
This
|
a4fc20f
to
6b07e4f
Compare
I am certainly against using Swapping error type based on the target does not look like a simplification to me, even worse I have a hunch that it will only cause weird issues in future. Also it looks like you assume that Overall, motivation of this rework looks a bit weak to me. Looks like the main driving factor is desire to improve @dhardy |
Meanwhile can you please submit |
So there are two issues here:
The switching on
So this is actually why I think having a |
I agree with most of what @newpavlov says; from the API perspective this isn't a simplification, and you haven't attempted to explain how this works with
Nor do I see why we should do so — the source code is public, and the only reason I can think of why anyone would need to do this is to work around some weird issue. (We don't even report "transient" failures any more.) |
Sure! After that, should I put that changes that call |
That's fair, but if we don't want users to match on the type, then shouldn't the return type be more opaque, not less? |
How does this work on platforms not able to use
We can't accept this PR as is for a number of reasons, one of which is the additional dependency on |
So like the one's that use RDRAND? Then |
Another argument against using target-dependent type is potential future addition of Why users need to know that it was an OS error? Assuming we will have a good error description, I don't think it should matter. |
That's a really good point I had not thought of. If that's the case then it might be even easier to just ditch having any information at all in the error type. Error's in Edit: Additional error context would be provided via the It also makes it so much easier to remove |
I think None of the 3 reasons stated in the |
79ed2b7
to
ba70371
Compare
@newpavlov @dhardy I significantly reworked this PR to incorporate your recommendations. The PR description has been updated. PTAL This change now focuses more on removing |
@dhardy @newpavlov I've rebased this and changed |
Sorry for the delay — I'd like to review again, but I think I'm happy with it. I am however waiting for @newpavlov to reply to my previous comment (about reserving blocks). |
Sorry for the late reply! I still don't see raison d'etre for What exact problem are you trying to solve here? Formatting can be improved without any issues separately from these API changes. |
The way I see it, @newpavlov has a good point about avoiding the need for panic and eliminating The |
This makes sense, I removed I also just did away with the whole block nonsense. After looking at it with a fresh set of eyes it seems unnecessarily complex. The reservations are now just:
The PR description and docs comments have also been updated/clarified. The |
Note that adding in the |
Is there an easy work-around for rustc 1.32? While most Rand users are happy to use the latest stable, there are a few less happy about it (for versions < 6 months old — 1.33 is almost that old now). |
What feature do we need from Rust 1.33? Is it about making const UNKNOWN_IO_ERROR: Error = Error(unsafe {
NonZeroU32::new_unchecked(Error::INTERNAL_START + 1)
}); Also I think you could use a macro if you don't like such explicitness. I will try to review changes on this weekend. |
I won't do anything before @newpavlov has a chance to review, but mostly I'm happy about this. Integration into Perhaps we should consider them internal and use from |
My thought was to have all the codes in I don't know how explicit you want to make the split between @newpavlov good idea, I'll just turn the function into a macro. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have several nitpicks in addition to the MSRV issue, but otherwise looks great!
Great! Thank you! |
One small thing which bothers me a bit is |
I guess it's just to ensure than no constants are too large? It's harmless anyway. |
Yes, before the function just took a u16, to ensure that the |
It looks like that rust-random/getrandom#54 has wrongly assigned us to Darwin case. The __error() is not libc callable function, but rather inline helper implemented at headers level to assist code that was using errno incorrectly. It seems that thread_local has still not become stable feature in rust? If this very useful language feature does not get official support soon enough in rust, it would be trivial for us to add simple helper function in libc using the most common __errno_location() variant out there. Since I could not figure out how to disable -Werror on this warning when using "extern { #[thread_local] static errno: c_int; }", just bringing back the previous crate helper that worked (using google search).
Edit: Significantly revised to account for earlier feedback. Depends on #57 (for
fill_exact
)The PR allows for error handling to work without depending on
libstd
, it also cleans up theError
type. Specifically:Error
type maintains itsNonZeroU32
representation. But now instead of holding a single code, it holds one of two values:i32
valueu32
value larger thani32::MAX
.Debug
andDisplay
implementations for OS Errors (on UNIX) by usinglibc::strerror_r
.Debug
andDisplay
implementations for Custom Errors (on some platforms) by defining additional error constants (instead of just returningError::UNKNOWN
)util_libc::last_os_error()
replacesstd::io::Error::last_os_error()
.Now the only things that depend on
libstd
are:std
feature