1use core::fmt;
3use core::result;
4use std::{error, io};
5
6#[derive(Debug)]
7pub enum Error {
9 ParseOutput(String),
11 NoFile(String),
13 IO(io::Error),
15 StacktraceParse(String),
17 SiginfoParse(String),
19 MappedFilesParse(String),
21 MemoryObjectParse(String),
23 IntParse(std::num::ParseIntError),
25 Gdb(String),
27}
28
29impl error::Error for Error {
30 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
31 match *self {
32 Error::IO(ref io) => Some(io),
33 Error::IntParse(ref pr) => Some(pr),
34 Error::ParseOutput(_) => None,
35 Error::NoFile(_) => None,
36 Error::StacktraceParse(_) => None,
37 Error::SiginfoParse(_) => None,
38 Error::MappedFilesParse(_) => None,
39 Error::MemoryObjectParse(_) => None,
40 Error::Gdb(_) => None,
41 }
42 }
43}
44
45impl From<io::Error> for Error {
46 fn from(err: io::Error) -> Error {
47 Error::IO(err)
48 }
49}
50
51impl From<std::num::ParseIntError> for Error {
52 fn from(err: std::num::ParseIntError) -> Error {
53 Error::IntParse(err)
54 }
55}
56
57impl fmt::Display for Error {
58 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
59 match *self {
60 Error::IO(ref err) => write!(fmt, "{err}"),
61 Error::IntParse(ref err) => write!(fmt, "{err}"),
62 Error::ParseOutput(ref msg) => write!(fmt, "Gdb parsing output error: {msg}"),
63 Error::NoFile(ref msg) => write!(fmt, "File not found: {msg}"),
64 Error::StacktraceParse(ref msg) => write!(fmt, "Error parsing stack trace: {msg}"),
65 Error::SiginfoParse(ref msg) => write!(fmt, "Error parsing siginfo: {msg}"),
66 Error::MappedFilesParse(ref msg) => write!(fmt, "Error parsing mapped files: {msg}"),
67 Error::MemoryObjectParse(ref msg) => {
68 write!(fmt, "Error parsing memory object: {msg}")
69 }
70 Error::Gdb(ref msg) => write!(fmt, "Failed to launch GDB: {msg}"),
71 }
72 }
73}
74
75pub type Result<T> = result::Result<T, Error>;