Common: Simplify raising of InvalidConfigurationError

This commit is contained in:
Mike Salvatore 2022-07-06 16:03:12 -04:00
parent 92416cb079
commit 82fb693f06
1 changed files with 9 additions and 6 deletions

View File

@ -17,16 +17,19 @@ from .agent_sub_configurations import (
PropagationConfiguration, PropagationConfiguration,
) )
class InvalidConfigurationError(Exception):
pass
INVALID_CONFIGURATION_ERROR_MESSAGE = ( INVALID_CONFIGURATION_ERROR_MESSAGE = (
"Cannot construct an AgentConfiguration object with the supplied, invalid data:" "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) @dataclass(frozen=True)
class AgentConfiguration: class AgentConfiguration:
keep_tunnel_open_time: float keep_tunnel_open_time: float
@ -42,7 +45,7 @@ class AgentConfiguration:
try: try:
AgentConfigurationSchema().dump(self) AgentConfigurationSchema().dump(self)
except Exception as err: except Exception as err:
raise InvalidConfigurationError(f"{INVALID_CONFIGURATION_ERROR_MESSAGE}: {err}") raise InvalidConfigurationError(err)
@staticmethod @staticmethod
def from_mapping(config_mapping: Mapping[str, Any]) -> AgentConfiguration: def from_mapping(config_mapping: Mapping[str, Any]) -> AgentConfiguration: