use std::io;
pub(crate) fn result(code: i32, operation: &str) -> io::Result<()> {
match code {
0 => Ok(()),
3 => Err(io::Error::from(io::ErrorKind::PermissionDenied)),
4 => Err(io::Error::from(io::ErrorKind::Unsupported)),
5 => Err(io::Error::from(io::ErrorKind::NotFound)),
_ if code as u32 == 0x80041320 => Err(io::Error::from(io::ErrorKind::Unsupported)),
_ => Err(io::Error::new(
io::ErrorKind::Other,
format!(
"Task Scheduler {operation} failed (HRESULT 0x{:08x})",
code as u32
),
)),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn existing_control_results_remain_distinct() {
assert!(result(0, "run").is_ok());
for (code, kind) in [
(3, io::ErrorKind::PermissionDenied),
(4, io::ErrorKind::Unsupported),
(5, io::ErrorKind::NotFound),
(6, io::ErrorKind::Other),
] {
assert_eq!(result(code, "run").unwrap_err().kind(), kind);
}
}
#[test]
fn unavailable_interactive_session_is_unsupported() {
assert_eq!(
result(0x80041320_u32 as i32, "run").unwrap_err().kind(),
io::ErrorKind::Unsupported
);
}
}