improve error handling

This commit is contained in:
Jan Petykiewicz 2024-08-01 00:20:53 -07:00
parent 42c69867b8
commit fec96b92a7
2 changed files with 6 additions and 7 deletions

View File

@ -341,7 +341,7 @@ class Process(metaclass=ABCMeta):
self.read_memory(start, region_buffer)
found += [offset + start for offset in search(needle_buffer, region_buffer)]
except OSError:
logger.error('Failed to read in range 0x{} - 0x{}'.format(start, stop))
logger.exception(f'Failed to read in range 0x{start} - 0x{stop}')
return found
@classmethod

View File

@ -161,8 +161,8 @@ class Process(AbstractProcess):
ctypes.sizeof(write_buffer),
None
)
except (BufferError, ValueError, TypeError):
raise MemEditError(f'Error with handle {self.process_handle}: {self._get_last_error()}')
except (BufferError, ValueError, TypeError) as err:
raise MemEditError(f'Error with handle {self.process_handle}: {self._get_last_error()}') from err
def read_memory(self, base_address: int, read_buffer: ctypes_buffer_t) -> ctypes_buffer_t:
try:
@ -173,8 +173,8 @@ class Process(AbstractProcess):
ctypes.sizeof(read_buffer),
None
)
except (BufferError, ValueError, TypeError):
raise MemEditError(f'Error with handle {self.process_handle}: {self._get_last_error()}')
except (BufferError, ValueError, TypeError) as err:
raise MemEditError(f'Error with handle {self.process_handle}: {self._get_last_error()}') from err
return read_buffer
@ -274,8 +274,7 @@ class Process(AbstractProcess):
if success == 0:
raise MemEditError('Failed VirtualQueryEx with handle '
+ f'{self.process_handle}: {self._get_last_error()}')
else:
raise MemEditError('VirtualQueryEx output too short!')
raise MemEditError('VirtualQueryEx output too short!')
return mbi