From 8f46b3b9fdce4d1efd3bf4b27a3901f11d87da0a Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 28 Sep 2022 19:55:52 +0530 Subject: [PATCH] Island: Make FileNotFoundError inherit UnknownRecordError instead of RetrievalError + add TODO for updating the rest of the code --- .../cc/repository/file_agent_log_repository.py | 10 +--------- .../monkey_island/cc/repository/i_file_repository.py | 5 +++-- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/monkey/monkey_island/cc/repository/file_agent_log_repository.py b/monkey/monkey_island/cc/repository/file_agent_log_repository.py index 51808cde0..728d16da8 100644 --- a/monkey/monkey_island/cc/repository/file_agent_log_repository.py +++ b/monkey/monkey_island/cc/repository/file_agent_log_repository.py @@ -1,14 +1,8 @@ import io import re -from monkey_island.cc import repository from monkey_island.cc.models import AgentID -from monkey_island.cc.repository import ( - IAgentLogRepository, - IFileRepository, - RetrievalError, - UnknownRecordError, -) +from monkey_island.cc.repository import IAgentLogRepository, IFileRepository, RetrievalError AGENT_LOG_FILE_NAME_PATTERN = "agent-*.log" AGENT_LOG_FILE_NAME_REGEX = re.compile(r"^agent-[\w-]+.log$") @@ -28,8 +22,6 @@ class FileAgentLogRepository(IAgentLogRepository): with self._file_repository.open_file(self._get_agent_log_file_name(agent_id)) as f: log_contents = f.read().decode() return log_contents - except repository.FileNotFoundError as err: - raise UnknownRecordError(err) except Exception as err: raise RetrievalError(f"Error retrieving the agent logs: {err}") diff --git a/monkey/monkey_island/cc/repository/i_file_repository.py b/monkey/monkey_island/cc/repository/i_file_repository.py index 877079dd3..3461186d2 100644 --- a/monkey/monkey_island/cc/repository/i_file_repository.py +++ b/monkey/monkey_island/cc/repository/i_file_repository.py @@ -1,10 +1,11 @@ import abc from typing import BinaryIO -from monkey_island.cc.repository import RetrievalError +from monkey_island.cc.repository import UnknownRecordError -class FileNotFoundError(RetrievalError): +# TODO: Remove this and use UnknownRecordError directly wherever needed. +class FileNotFoundError(UnknownRecordError): pass