diff --git a/src/caoscrawler/exceptions.py b/src/caoscrawler/exceptions.py index e7c61c34e2abbebef4790bde42f50d4b5b29f957..b9b94e1d4f9064701e8e05e22f5a0d3c6d3291a9 100644 --- a/src/caoscrawler/exceptions.py +++ b/src/caoscrawler/exceptions.py @@ -20,6 +20,9 @@ # along with this program. If not, see <https://www.gnu.org/licenses/>. # +from typing import Any + + class ForbiddenTransaction(Exception): """Thrown if an transactions is needed that is not allowed. For example an update of an entity if the security level is INSERT @@ -30,12 +33,40 @@ class ForbiddenTransaction(Exception): class ImpossibleMergeError(Exception): """Thrown if due to identifying information, two SyncNodes or two Properties of SyncNodes should be merged, but there is conflicting information that prevents this. + + Parameters + ---------- + msg : str + A case-specific error message describing where the merger error occurred. + pname : str + The name of the property the values of which caused the merge error. + value_a, value_b : Any + The two values that couldn't be merged. + + Attributes + ---------- + message : str + A case-specific error message describing where the merger error occurred. + values : tuple[Any] + The two values that couldn't be merged. + pname : str + The name of the property the values of which caused the merge error. """ - def __init__(self, *args, pname, values, **kwargs): + def __init__(self, msg: str, pname: str, value_a: Any, value_b: Any): self.pname = pname - self.values = values - super().__init__(self, *args, **kwargs) + self.values = (value_a, value_b) + self.message = msg + super().__init__(self, msg) + + def __str__(self): + return ( + f"{self.message}\n\nThe problematic property is '{self.pname}' with " + f"values '{self.values[0]}' and '{self.values[1]}'." + ) + + def __repr__(self): + return self.__str__() class InvalidIdentifiableYAML(Exception):