This commit is contained in:
Swapna Lekkala 2025-11-13 13:57:05 -08:00
parent 33c7bd6c09
commit c40597bee3

View file

@ -17,17 +17,12 @@ logger = get_logger(name=__name__)
class RuntimeErrorRule: class RuntimeErrorRule:
code: str code: str
default_message: str default_message: str
substrings: tuple[str, ...] = ()
regex: re.Pattern[str] | None = None regex: re.Pattern[str] | None = None
template: str | None = None template: str | None = None
def evaluate(self, error_msg: str) -> str | None: def evaluate(self, error_msg: str) -> str | None:
""" """Return the sanitized message if this rule matches, otherwise None."""
Returns the sanitized message if the rule matches, otherwise None. if self.regex and (match := self.regex.search(error_msg)):
"""
if self.regex:
match = self.regex.search(error_msg)
if match:
if self.template: if self.template:
try: try:
return self.template.format(**match.groupdict()) return self.template.format(**match.groupdict())
@ -35,10 +30,6 @@ class RuntimeErrorRule:
logger.debug("Failed to format sanitized runtime error message", exc_info=True) logger.debug("Failed to format sanitized runtime error message", exc_info=True)
return self.default_message return self.default_message
lowered = error_msg.lower()
if self.substrings and all(pattern in lowered for pattern in self.substrings):
return self.default_message
return None return None