From 6511d02414ec9dd4bcaa237336c5f74869e6c41a Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 6 Jun 2021 10:43:02 -0600 Subject: 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. 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. 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 #1155 --- test/sys/test_termios.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/sys/test_termios.rs') diff --git a/test/sys/test_termios.rs b/test/sys/test_termios.rs index 00aeb2fc..ce436a13 100644 --- a/test/sys/test_termios.rs +++ b/test/sys/test_termios.rs @@ -32,14 +32,14 @@ fn test_tcgetattr_pty() { fn test_tcgetattr_enotty() { let file = tempfile().unwrap(); assert_eq!(termios::tcgetattr(file.as_raw_fd()).err(), - Some(Error::Sys(Errno::ENOTTY))); + Some(Error(Errno::ENOTTY))); } // Test tcgetattr on an invalid file descriptor #[test] fn test_tcgetattr_ebadf() { assert_eq!(termios::tcgetattr(-1).err(), - Some(Error::Sys(Errno::EBADF))); + Some(Error(Errno::EBADF))); } // Test modifying output flags @@ -126,5 +126,5 @@ fn test_local_flags() { let read = read(pty.master, &mut buf).unwrap_err(); close(pty.master).unwrap(); close(pty.slave).unwrap(); - assert_eq!(read, Error::Sys(Errno::EAGAIN)); + assert_eq!(read, Error(Errno::EAGAIN)); } -- cgit v1.2.3