human_errors/from/
std_io.rs

1use crate::{Error, wrap_system, wrap_user};
2use std::io;
3
4impl From<io::Error> for Error {
5    fn from(err: io::Error) -> Self {
6        match err.kind() {
7            io::ErrorKind::NotFound => wrap_user(
8                err,
9                "Could not find the requested file.",
10                &["Check that the file path you provided is correct and try again."],
11            ),
12            io::ErrorKind::PermissionDenied => wrap_user(
13                err,
14                "Permission denied when trying to access the requested resource.",
15                &[
16                    "Check the file permissions and ensure that the application has access to the resource.",
17                ],
18            ),
19            io::ErrorKind::AlreadyExists => wrap_user(
20                err,
21                "The file or directory you are trying to create already exists.",
22                &["Choose a different file name or delete the existing file and try again."],
23            ),
24            io::ErrorKind::AddrInUse => wrap_user(
25                err,
26                "The network address you are trying to bind to is already in use.",
27                &["Make sure no other application is using the same address and try again."],
28            ),
29            io::ErrorKind::DirectoryNotEmpty => wrap_user(
30                err,
31                "The directory you are trying to remove is not empty.",
32                &[
33                    "Delete all files and subdirectories within the directory before attempting to remove it.",
34                ],
35            ),
36            _ => wrap_system(
37                err,
38                "An internal error occurred which we could not recover from.",
39                &[
40                    "Please read the internal error below and decide if there is something you can do to fix the problem, or report it to us on GitHub.",
41                ],
42            ),
43        }
44    }
45}