forked from p15670423/monkey
Common: Remove INVALID_CONFIGURATION_ERROR_MESSAGE
This commit is contained in:
parent
a18eb1cb73
commit
6bb6aa5250
|
@ -17,17 +17,16 @@ from .agent_sub_configurations import (
|
||||||
PropagationConfiguration,
|
PropagationConfiguration,
|
||||||
)
|
)
|
||||||
|
|
||||||
INVALID_CONFIGURATION_ERROR_MESSAGE = (
|
|
||||||
"Cannot construct an AgentConfiguration object with the supplied, invalid data:"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class InvalidConfigurationError(Exception):
|
class InvalidConfigurationError(Exception):
|
||||||
def __init__(self, message: str):
|
def __init__(self, message: str):
|
||||||
self._message = message
|
self._message = message
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"{INVALID_CONFIGURATION_ERROR_MESSAGE}: {self._message}"
|
return (
|
||||||
|
f"Cannot construct an AgentConfiguration object with the supplied, invalid data: "
|
||||||
|
f"{self._message}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
|
@ -45,7 +44,7 @@ class AgentConfiguration:
|
||||||
try:
|
try:
|
||||||
AgentConfigurationSchema().dump(self)
|
AgentConfigurationSchema().dump(self)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
raise InvalidConfigurationError(err)
|
raise InvalidConfigurationError(str(err))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_mapping(config_mapping: Mapping[str, Any]) -> AgentConfiguration:
|
def from_mapping(config_mapping: Mapping[str, Any]) -> AgentConfiguration:
|
||||||
|
@ -62,7 +61,7 @@ class AgentConfiguration:
|
||||||
config_dict = AgentConfigurationSchema().load(config_mapping)
|
config_dict = AgentConfigurationSchema().load(config_mapping)
|
||||||
return AgentConfiguration(**config_dict)
|
return AgentConfiguration(**config_dict)
|
||||||
except MarshmallowError as err:
|
except MarshmallowError as err:
|
||||||
raise InvalidConfigurationError(f"{INVALID_CONFIGURATION_ERROR_MESSAGE}: {err}")
|
raise InvalidConfigurationError(str(err))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_json(config_json: str) -> AgentConfiguration:
|
def from_json(config_json: str) -> AgentConfiguration:
|
||||||
|
@ -78,7 +77,7 @@ class AgentConfiguration:
|
||||||
config_dict = AgentConfigurationSchema().loads(config_json)
|
config_dict = AgentConfigurationSchema().loads(config_json)
|
||||||
return AgentConfiguration(**config_dict)
|
return AgentConfiguration(**config_dict)
|
||||||
except MarshmallowError as err:
|
except MarshmallowError as err:
|
||||||
raise InvalidConfigurationError(f"{INVALID_CONFIGURATION_ERROR_MESSAGE}: {err}")
|
raise InvalidConfigurationError(str(err))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def to_json(config: AgentConfiguration) -> str:
|
def to_json(config: AgentConfiguration) -> str:
|
||||||
|
|
Loading…
Reference in New Issue