From 82fb693f064f13619366cf733f6adf998f519e68 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 6 Jul 2022 16:03:12 -0400 Subject: [PATCH] Common: Simplify raising of InvalidConfigurationError --- .../common/configuration/agent_configuration.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/monkey/common/configuration/agent_configuration.py b/monkey/common/configuration/agent_configuration.py index 097b86382..5b801610d 100644 --- a/monkey/common/configuration/agent_configuration.py +++ b/monkey/common/configuration/agent_configuration.py @@ -17,16 +17,19 @@ from .agent_sub_configurations import ( PropagationConfiguration, ) - -class InvalidConfigurationError(Exception): - pass - - INVALID_CONFIGURATION_ERROR_MESSAGE = ( "Cannot construct an AgentConfiguration object with the supplied, invalid data:" ) +class InvalidConfigurationError(Exception): + def __init__(self, message: str): + self._message = message + + def __str__(self) -> str: + return f"{INVALID_CONFIGURATION_ERROR_MESSAGE}: {self._message}" + + @dataclass(frozen=True) class AgentConfiguration: keep_tunnel_open_time: float @@ -42,7 +45,7 @@ class AgentConfiguration: try: AgentConfigurationSchema().dump(self) except Exception as err: - raise InvalidConfigurationError(f"{INVALID_CONFIGURATION_ERROR_MESSAGE}: {err}") + raise InvalidConfigurationError(err) @staticmethod def from_mapping(config_mapping: Mapping[str, Any]) -> AgentConfiguration: