make Error enum variants clearer
This commit is contained in:
+4
-4
@@ -3,13 +3,13 @@ use thiserror::Error;
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
#[error("failed to obtain handle")]
|
||||
HandleError(String),
|
||||
ObtainHandleError(String),
|
||||
#[error("failed to access process memory")]
|
||||
MemoryError(String),
|
||||
AccessMemoryError(String),
|
||||
#[error("failed to create process")]
|
||||
ProcessError(String),
|
||||
CreateProcessError(String),
|
||||
#[error("failed to create snapshot")]
|
||||
SnapshotError(String),
|
||||
CreateSnapshotError(String),
|
||||
#[error("failed to convert integer")]
|
||||
ConvertIntegerError(#[from] std::num::TryFromIntError),
|
||||
}
|
||||
|
||||
@@ -35,13 +35,13 @@ impl Handle {
|
||||
OpenProcess(PROCESS_ALL_ACCESS, false, pid)
|
||||
.or_else(|_| OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE, false, pid))
|
||||
.map_err(|why| {
|
||||
crate::Error::HandleError(format!(
|
||||
crate::Error::ObtainHandleError(format!(
|
||||
"failed to open process with needed access: {why}",
|
||||
))
|
||||
})?
|
||||
};
|
||||
if handle == INVALID_HANDLE_VALUE {
|
||||
return Err(crate::Error::HandleError(
|
||||
return Err(crate::Error::ObtainHandleError(
|
||||
"failed to get a valid handle".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ pub fn read<T>(handle: &Handle, address: usize, value: &mut T) -> Result<(), cra
|
||||
None,
|
||||
) {
|
||||
Ok(()) => Ok(()),
|
||||
Err(why) => Err(crate::Error::MemoryError(format!(
|
||||
Err(why) => Err(crate::Error::AccessMemoryError(format!(
|
||||
"failed to read memory: {why}"
|
||||
))),
|
||||
}
|
||||
@@ -31,7 +31,7 @@ pub fn write<T>(handle: &Handle, address: usize, value: &mut T) -> Result<(), cr
|
||||
None,
|
||||
) {
|
||||
Ok(()) => Ok(()),
|
||||
Err(why) => Err(crate::Error::MemoryError(format!(
|
||||
Err(why) => Err(crate::Error::AccessMemoryError(format!(
|
||||
"failed to write memory: {why}"
|
||||
))),
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ impl Process {
|
||||
.into_iter()
|
||||
.find(|snapshot| snapshot.name == *name),
|
||||
}) else {
|
||||
return Err(crate::Error::ProcessError(format!(
|
||||
return Err(crate::Error::CreateProcessError(format!(
|
||||
"failed to find a process with identifier `{identifier}`",
|
||||
)));
|
||||
};
|
||||
@@ -61,7 +61,7 @@ impl Process {
|
||||
.into_iter()
|
||||
.find(|snapshot| snapshot.name == name)
|
||||
else {
|
||||
return Err(crate::Error::ProcessError(format!(
|
||||
return Err(crate::Error::CreateProcessError(format!(
|
||||
"failed to find a module with identifier `{name}`",
|
||||
)));
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ impl ProcessSnapshot {
|
||||
match CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) {
|
||||
Ok(snapshot) => snapshot,
|
||||
Err(why) => {
|
||||
return Err(crate::Error::SnapshotError(format!(
|
||||
return Err(crate::Error::CreateSnapshotError(format!(
|
||||
"failed to create process snapshot: {why}"
|
||||
)))
|
||||
}
|
||||
@@ -31,7 +31,7 @@ impl ProcessSnapshot {
|
||||
match Process32FirstW(snapshot, &mut process_entry_32_w) {
|
||||
Ok(()) => {}
|
||||
Err(why) => {
|
||||
return Err(crate::Error::SnapshotError(format!(
|
||||
return Err(crate::Error::CreateSnapshotError(format!(
|
||||
"failed to get first process from snapshot: {why}"
|
||||
)))
|
||||
}
|
||||
@@ -71,7 +71,7 @@ impl ModuleSnapshot {
|
||||
match CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, pid) {
|
||||
Ok(snapshot) => snapshot,
|
||||
Err(why) => {
|
||||
return Err(crate::Error::SnapshotError(format!(
|
||||
return Err(crate::Error::CreateSnapshotError(format!(
|
||||
"failed to create module snapshot: {why}"
|
||||
)))
|
||||
}
|
||||
@@ -85,7 +85,7 @@ impl ModuleSnapshot {
|
||||
match Module32FirstW(snapshot, &mut module_entry_32_w) {
|
||||
Ok(()) => {}
|
||||
Err(why) => {
|
||||
return Err(crate::Error::SnapshotError(format!(
|
||||
return Err(crate::Error::CreateSnapshotError(format!(
|
||||
"failed to get first module from snapshot: {why}"
|
||||
)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user