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

Overhaul Nix's error types #1446

Merged
merged 4 commits into from Jul 8, 2021
Merged

Overhaul Nix's error types #1446

merged 4 commits into from Jul 8, 2021

Commits on Jul 8, 2021

  1. Copy the full SHA
    f90033e View commit details
    Browse the repository at this point in the history
  2. Overhaul Nix's error types

    For many of Nix's consumers it be convenient to easily convert a Nix
    error into a std::io::Error.  That's currently not possible because of
    the InvalidPath, InvalidUtf8, and UnsupportedOperation types that have
    no equivalent in std::io::Error.
    
    However, very few of Nix's public APIs actually return those unusual
    errors.  So a more useful API would be for Nix's standard error type to
    implement Into<std::io::Error>.
    
    This commit makes Error a simple NewType around Errno.  For most
    functions it's a drop-in replacement.  There are only three exceptions:
    
    * clearenv now returns a bespoke error type.  It was the only Nix
      function whose error couldn't be cleanly mapped onto an Errno.
    
    * sys::signal::signal now returns Error(Errno::ENOTSUP) instead of
      Error::UnsupportedOperation when the user passes an incompatible
      argument to `handler`.
    
    * When a NixPath exceeds PATH_MAX, it will now return
      Error(Errno::ENAMETOOLONG) instead of Error::InvalidPath.
    
    In the latter two cases there is now some abiguity about whether the
    error code was generated by Nix or by the OS.  But I think the ambiguity
    is worth it for the sake of being able to implement Into<io::Error>.
    
    This commit also introduces Error::Sys() as a migration aid.  Previously
    that as an enum variant.  Now it's a function, but it will work in many
    of the same contexts as the original.
    
    Fixes nix-rust#1155
    asomers committed Jul 8, 2021
    Copy the full SHA
    6511d02 View commit details
    Browse the repository at this point in the history
  3. Collapse Error into Errno

    Now that Nix's weird error types are eliminated, there's no reason not
    to simply use Errno as the Error type.
    asomers committed Jul 8, 2021
    Copy the full SHA
    2d796eb View commit details
    Browse the repository at this point in the history
  4. Copy the full SHA
    714d6e9 View commit details
    Browse the repository at this point in the history