use std::io::ErrorKind;
pub(crate) fn report(error: &anyhow::Error) {
eprintln!("servio: {error:#}");
}
pub(crate) fn cannot_reach(doing: String, error: &std::io::Error) -> anyhow::Error {
anyhow::Error::msg(why(error)).context(doing)
}
pub(crate) fn why(error: &std::io::Error) -> String {
match error.kind() {
ErrorKind::NotFound => "there is no such directory".to_string(),
ErrorKind::PermissionDenied => "the system will not let this program read it".to_string(),
ErrorKind::NotADirectory => "part of that path is a file, not a directory".to_string(),
ErrorKind::IsADirectory => "it is a directory, not a file".to_string(),
_ if cfg!(unix) && matches!(error.raw_os_error(), Some(23 | 24)) => {
"the system has no open files left for this program — close some programs, or raise the limit".to_string()
}
_ => error.to_string(),
}
}