From 5b5be39b19f11b7c94bfb7842541bc71da64f7b8 Mon Sep 17 00:00:00 2001 From: Kislay Verma Date: Fri, 28 Mar 2025 09:20:50 +0530 Subject: [PATCH] exceptions: Create base class ExpectationMismatchError. This class will be inherited by all errors related to some sort of mismatch from the expected value. This is a prep commit for #33051, as a part of which we add a new exception class for message content mismatch. --- zerver/lib/exceptions.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/zerver/lib/exceptions.py b/zerver/lib/exceptions.py index 38bcf8947a..0c154d0459 100644 --- a/zerver/lib/exceptions.py +++ b/zerver/lib/exceptions.py @@ -684,16 +684,29 @@ class TopicWildcardMentionNotAllowedError(JsonableError): return _("You do not have permission to use topic wildcard mentions in this topic.") -class PreviousSettingValueMismatchedError(JsonableError): +class ExpectationMismatchError(JsonableError): code: ErrorCode = ErrorCode.EXPECTATION_MISMATCH + data_fields = ["field_name"] def __init__(self) -> None: - pass + self.field_name = "field" @staticmethod @override def msg_format() -> str: - return _("'old' value does not match the expected value.") + return _("'{field_name}' value does not match the expected value.") + + +class PreviousSettingValueMismatchedError(ExpectationMismatchError): + def __init__(self) -> None: + super().__init__() + self.field_name = "old" + + +class PreviousMessageContentMismatchedError(ExpectationMismatchError): + def __init__(self) -> None: + super().__init__() + self.field_name = "prev_content_sha256" class SystemGroupRequiredError(JsonableError):