summaryrefslogtreecommitdiff
path: root/test/test_mq.rs
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2021-06-06 10:43:02 -0600
committerAlan Somers <asomers@gmail.com>2021-07-07 20:49:28 -0600
commit6511d02414ec9dd4bcaa237336c5f74869e6c41a (patch)
tree61e6cde2230efb026e9ac9c6a6e786cb6ba77642 /test/test_mq.rs
parentf90033ed35af02f39d4eaf28eff85f226c10d91b (diff)
downloadnix-6511d02414ec9dd4bcaa237336c5f74869e6c41a.zip
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 #1155
Diffstat (limited to 'test/test_mq.rs')
-rw-r--r--test/test_mq.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/test/test_mq.rs b/test/test_mq.rs
index 1667a35b..e16103fb 100644
--- a/test/test_mq.rs
+++ b/test/test_mq.rs
@@ -1,8 +1,8 @@
use std::ffi::CString;
use std::str;
-use nix::errno::Errno::*;
-use nix::Error::Sys;
+use nix::errno::Errno;
+use nix::Error;
use nix::mqueue::{mq_open, mq_close, mq_send, mq_receive, mq_attr_member_t};
use nix::mqueue::{MqAttr, MQ_OFlag};
use nix::sys::stat::Mode;
@@ -16,7 +16,7 @@ fn test_mq_send_and_receive() {
let oflag0 = MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY;
let mode = Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH;
let r0 = mq_open(mq_name, oflag0, mode, Some(&attr));
- if let Err(Sys(ENOSYS)) = r0 {
+ if let Err(Error(Errno::ENOSYS)) = r0 {
println!("message queues not supported or module not loaded?");
return;
};
@@ -47,7 +47,7 @@ fn test_mq_getattr() {
let oflag = MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY;
let mode = Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH;
let r = mq_open(mq_name, oflag, mode, Some(&initial_attr));
- if let Err(Sys(ENOSYS)) = r {
+ if let Err(Error(Errno::ENOSYS)) = r {
println!("message queues not supported or module not loaded?");
return;
};
@@ -70,7 +70,7 @@ fn test_mq_setattr() {
let oflag = MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY;
let mode = Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH;
let r = mq_open(mq_name, oflag, mode, Some(&initial_attr));
- if let Err(Sys(ENOSYS)) = r {
+ if let Err(Error(Errno::ENOSYS)) = r {
println!("message queues not supported or module not loaded?");
return;
};
@@ -107,7 +107,7 @@ fn test_mq_set_nonblocking() {
let oflag = MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY;
let mode = Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH;
let r = mq_open(mq_name, oflag, mode, Some(&initial_attr));
- if let Err(Sys(ENOSYS)) = r {
+ if let Err(Error(Errno::ENOSYS)) = r {
println!("message queues not supported or module not loaded?");
return;
};
@@ -132,7 +132,7 @@ fn test_mq_unlink() {
let oflag = MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY;
let mode = Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH;
let r = mq_open(mq_name_opened, oflag, mode, Some(&initial_attr));
- if let Err(Sys(ENOSYS)) = r {
+ if let Err(Error(Errno::ENOSYS)) = r {
println!("message queues not supported or module not loaded?");
return;
};
@@ -142,9 +142,9 @@ fn test_mq_unlink() {
assert_eq!(res_unlink, Ok(()) );
let res_unlink_not_opened = mq_unlink(mq_name_not_opened);
- assert_eq!(res_unlink_not_opened, Err(Sys(ENOENT)) );
+ assert_eq!(res_unlink_not_opened, Err(Error(Errno::ENOENT)) );
mq_close(mqd).unwrap();
let res_unlink_after_close = mq_unlink(mq_name_opened);
- assert_eq!(res_unlink_after_close, Err(Sys(ENOENT)) );
+ assert_eq!(res_unlink_after_close, Err(Error(Errno::ENOENT)) );
}