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

0.2: Error and Testing improvements #120

Merged
merged 10 commits into from
Oct 28, 2019
Merged

Conversation

josephlr
Copy link
Member

#109 contains a lot of fixes to the Error class and to our testing infrastructure that makes it harder to focus on the important changes in that PR.

I split out the changes unrelated to Custom RNGs into this PR. I also fixed up the commits/messages to explain these changes (we should be sure to "merge" this PR not "squash" it). Also, this PR should be merged before #109

This PR:

  • Improves the Error struct
    • Removes deprecated constants
    • Exposes new Error constants
    • Some other minor nits
  • Improves our Testing code
    • Remove use of --examples, we do not have examples
    • Install drivers to $HOME
    • Use YAML expansion to avoid repeating testing configs
    • Ensure crates build with each feature set individually
    • Add missing targets to cross-platform build step
    • Check minimum version compatiblity with features on
    • Gerate docs with "std" feature set
  • Makes sure that the std feature will be enabled when using docs.rs.

- Remove use of `--examples`, we do not have examples
- Install drivers to $HOME
- Use YAML expansion to avoid repeating testing configs
- Make sure crates build with each feature set individually
- Add missing targets to cross-platform build step
- Check minimum version compatiblity with features _on_
- Gerate docs with "std" feature set
@josephlr josephlr requested review from newpavlov and dhardy October 26, 2019 09:50
@josephlr josephlr added this to the 0.2 milestone Oct 26, 2019
Copy link
Member

@dhardy dhardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

One addition I'd like to see (@newpavlov?) is to prefix more of these error constants (e.g. RAND_SECURE_FATAL) with the platform name (in this case VxWorks, which is mentioned in the error message).

Copy link
Member

@newpavlov newpavlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One addition I'd like to see is to prefix more of these error constants (e.g. RAND_SECURE_FATAL) with the platform name

Yes, sounds good to me.

@newpavlov
Copy link
Member

newpavlov commented Oct 27, 2019

BTW maybe we should cfg match arms in the internal_desc depending on the platform (or even constants themselves)? Otherwise all error description strings will get compiled on all platforms, even though most of them will never be used. Yes, it will be a really-really small improvement of a final binary size, but I guess every bit counts.

fn internal_desc(error: Error) -> Option<&'static str> {
    match error {
        Error::UNSUPPORTED => Some("getrandom: this target is not supported"),
        #[cfg(unix)]
        Error::ERRNO_NOT_POSITIVE => Some("errno: did not return a positive value"),
        Error::UNKNOWN_IO_ERROR => Some("Unknown std::io::Error"),
        #[cfg(target_os = "ios")]
        Error::SEC_RANDOM_FAILED => Some("SecRandomCopyBytes: call failed"),
        #[cfg(target_os = "windows")]
        Error::RTL_GEN_RANDOM_FAILED => Some("RtlGenRandom: call failed"),
        // ....
        _ => None,
    }
}

And I think we don't use From<io::Error> impl anymore, so we probably can remove it together with UNKNOWN_IO_ERROR.

Also remove Error::UNKNOWN_IO_ERROR constant
Also fixup documentation and error messages
@josephlr
Copy link
Member Author

Looks good to me.

One addition I'd like to see (@newpavlov?) is to prefix more of these error constants (e.g. RAND_SECURE_FATAL) with the platform name (in this case VxWorks, which is mentioned in the error message).

Done, changed to IOS_SEC_RANDOM, WINDOWS_RTL_GEN_RANDOM, VXWORKS_RAND_SECURE. I also updated the error messages/docs

BTW maybe we should cfg match arms in the internal_desc depending on the platform (or even constants themselves)?

So removing the strings makes the release binary smaller, but removing the constants themselves should only make the rlib smaller but have no affect on the final binary size (as they are constants, they don't have a place in memory).

I don't think we should remove the constants. As for removing the strings, doing it correctly for all of them is tricky (involving some gross cfg-if). I think we should discuss binary size reduction in a separate PR, and decide which metrics we care about.

And I think we don't use From<io::Error> impl anymore, so we probably can remove it together with UNKNOWN_IO_ERROR.

Done, removed.

@dhardy, @newpavlov if you like the changes, feel free to merge this (once the CI is green).

@newpavlov newpavlov merged commit 8096bac into rust-random:0.2 Oct 28, 2019
@dhardy
Copy link
Member

dhardy commented Oct 28, 2019

I don't think we should remove the constants. As for removing the strings, doing it correctly for all of them is tricky (involving some gross cfg-if). I think we should discuss binary size reduction in a separate PR, and decide which metrics we care about.

Agreed. Duplicating cfg-if spaghetti sounds like something best saved until later (potentially never, unless someone can make a good argument for it, but feel free to open an issue).

Changes look good to me.

@josephlr josephlr deleted the error branch October 28, 2019 10:36
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