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,
)
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: