mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-03 09:53:45 +00:00
update
This commit is contained in:
parent
33c7bd6c09
commit
c40597bee3
1 changed files with 7 additions and 16 deletions
|
|
@ -17,26 +17,17 @@ 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.template:
|
||||||
if self.regex:
|
try:
|
||||||
match = self.regex.search(error_msg)
|
return self.template.format(**match.groupdict())
|
||||||
if match:
|
except Exception: # pragma: no cover - defensive
|
||||||
if self.template:
|
logger.debug("Failed to format sanitized runtime error message", exc_info=True)
|
||||||
try:
|
|
||||||
return self.template.format(**match.groupdict())
|
|
||||||
except Exception: # pragma: no cover - defensive
|
|
||||||
logger.debug("Failed to format sanitized runtime error message", exc_info=True)
|
|
||||||
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 self.default_message
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue