Skip to content

move errno -> IoError converter into std, bubble up OSRng errors #13115

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

Merged
merged 3 commits into from
Apr 1, 2014

Conversation

huonw
Copy link
Member

@huonw huonw commented Mar 24, 2014

move errno -> IoError converter into std, bubble up OSRng errors

Also adds a general errno -> ~str converter to std::os, and makes the failure messages for the things using OSRng (e.g. (transitively) the task-local RNG, meaning hashmap initialisation failures aren't such a black box).

@huonw
Copy link
Member Author

huonw commented Mar 24, 2014

r? @alexcrichton

@alexcrichton
Copy link
Member

I was thinking for a bit that this is unfortunately leaking implementation details. On the other hand, I believe that generally accepted practice is that good RNGs are all seeded well, and the best seeds always come from the OS sources, all of which can reasonably fail.

With that in mind, I'm not too worried about the details leaking. r=me with my comments

@huonw
Copy link
Member Author

huonw commented Mar 25, 2014

With that in mind, I'm not too worried about the details leaking

Yeah, I was not so keen on that, but I can't see a sensible way around it (since internally squashing errors is barely sensible).


I'm also a little concerned that most people will just call .unwrap() and get a "unwrap called on Err" message rather than anything to do with (a) where it came from (i.e. completely disconnected from librand), or (b) what the error was (i.e. doesn't inspect the IoError at all).

This is a general problem with IoResult, but I think librand may suffer from it more than most other libs because many people will just want an RNG, and don't want to think about errors... which means when an error does happen they get far less information than they used to. (That said, task_rng is the one that fails most, due to HashMap, and it now has a nicer message; so I don't think this will be too concerning in practice.)

@huonw
Copy link
Member Author

huonw commented Mar 27, 2014

(Updated, will squash. Apologies for my initial embarrassingly low quality version of the second last commit, I was doing it rather too late at night. :( )

@alexcrichton
Copy link
Member

r=me, and no worries!

@alexcrichton
Copy link
Member

You may want to take a look at travis as well

huonw added 3 commits April 1, 2014 20:46
This also adds a direct `errno` -> `~str` converter, rather than only
being possible to get a string for the very last error.
The various ...Rng::new() methods can hit IO errors from the OSRng they use,
and it seems sensible to expose them at a higher level. Unfortunately, writing
e.g. `StdRng::new().unwrap()` gives a much poorer error message than if it
failed internally, but this is a problem with all `IoResult`s.
bors added a commit that referenced this pull request Apr 1, 2014
move errno -> IoError converter into std, bubble up OSRng errors

Also adds a general errno -> `~str` converter to `std::os`, and makes the failure messages for the things using `OSRng` (e.g. (transitively) the task-local RNG, meaning hashmap initialisation failures aren't such a black box).
@bors bors closed this Apr 1, 2014
@bors bors merged commit bc7a2d7 into rust-lang:master Apr 1, 2014
@huonw huonw deleted the rand-errors branch June 27, 2014 06:47
flip1995 pushed a commit to flip1995/rust that referenced this pull request Aug 8, 2024
Remove duplicated `peel_middle_ty_refs`

TODO: Should we move `ty::peel_mid_ty_refs_is_mutable` to super module too?

changelog: none
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

Successfully merging this pull request may close these issues.

3 participants