crash_handler/
error.rs

1use std::fmt;
2
3/// An error that can occur when attaching or detaching a [`crate::CrashHandler`]
4#[derive(Debug)]
5pub enum Error {
6    /// Unable to `mmap` memory
7    OutOfMemory,
8    /// For simplicity sake, only one [`crate::CrashHandler`] can be registered
9    /// at any one time.
10    HandlerAlreadyInstalled,
11    /// An I/O or other syscall failed
12    Io(std::io::Error),
13}
14
15impl std::error::Error for Error {
16    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
17        match self {
18            Self::Io(inner) => Some(inner),
19            _ => None,
20        }
21    }
22}
23
24impl fmt::Display for Error {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        match self {
27            Self::OutOfMemory => f.write_str("unable to allocate memory"),
28            Self::HandlerAlreadyInstalled => {
29                f.write_str("an exception handler is already installed")
30            }
31            Self::Io(e) => write!(f, "{}", e),
32        }
33    }
34}
35
36impl From<std::io::Error> for Error {
37    fn from(e: std::io::Error) -> Self {
38        Self::Io(e)
39    }
40}