1use std::{num::ParseIntError, string::FromUtf8Error};
2
3#[derive(thiserror::Error, Debug)]
4pub enum ProcessError {
5 #[error("process not found")]
6 ProcessNotFound,
7 #[error("executable path not found")]
8 ExecutablePathNotFound,
9 #[error("not enough permissions to run, please run as admin/sudo")]
10 NotEnoughPermissions,
11 #[error("io error")]
12 IoError(#[from] std::io::Error),
13 #[error("failed to convert bytes to string")]
14 FromUtf8Error,
15 #[error("failed to convert type")]
16 ConvertionError,
17 #[error("trying to read bad address, addr: {0:X}, len: {1:X}")]
18 BadAddress(usize, usize),
19 #[error("cannot find signature: {0}")]
20 SignatureNotFound(String),
21 #[error("failed to convert address to usize")]
22 AddressConvertError,
23 #[error("string is too large, over the limit")]
24 StringTooLarge,
25 #[cfg(target_os = "linux")]
26 #[error("os error `{0}`")]
27 OsError(#[from] nix::errno::Errno),
28 #[cfg(target_os = "windows")]
29 #[error("os error `{0}`")]
30 OsError(#[from] windows::core::Error),
31}
32
33impl From<std::num::ParseIntError> for ProcessError {
34 fn from(_: std::num::ParseIntError) -> Self {
35 Self::ConvertionError
36 }
37}
38
39impl From<FromUtf8Error> for ProcessError {
40 fn from(_: FromUtf8Error) -> Self {
41 Self::FromUtf8Error
42 }
43}
44
45impl From<std::str::Utf8Error> for ProcessError {
46 fn from(_: std::str::Utf8Error) -> Self {
47 Self::FromUtf8Error
48 }
49}
50
51#[derive(thiserror::Error, Debug)]
52pub enum ParseSignatureError {
53 #[error("invalid string length `{0}`")]
54 InvalidLength(usize),
55 #[error("failed to parse integer")]
56 InvalidInt(#[from] ParseIntError),
57}