"""Error hierarchy for the unified review queue.All review-layer errors inherit from :class:`ReviewError`, which inturn inherits from :class:`cadrumo.core.errors.hierarchy.CadrumoError` per theproject's package-wide error-base mandate. Callers can therefore catcheither :class:`ReviewError` for review-specific failures or thepackage-wide :exc:`cadrumo.core.errors.hierarchy.CadrumoError` to handle every aeatdomain error uniformly."""from__future__importannotationsfrom...core.errors.hierarchyimportCadrumoError
[docs]classReviewError(CadrumoError):"""Base class for every error raised by :mod:`cadrumo.application.review`."""
[docs]classReviewSourceLoadError(ReviewError):"""Raised when a source disk file is present but cannot be parsed."""
[docs]classFilterParseError(ReviewError):"""Raised when ``--filter KEY=VALUE`` cannot be parsed. Carries the raw token plus a stable reason code so the CLI can render a per-language repair hint. Attributes: raw_token: The string the operator supplied (e.g. ``"status="`` or ``"period: 1T"``). Stored as an internal diagnostic attribute, but omitted from rendered messages and context because filter values may include free-text search strings or imported identifiers. safe_token: A redacted token that preserves the key when it is parseable and replaces the value with ``<redacted>``. reason: One of ``"missing-equals"``, ``"empty-key"``, ``"empty-value"``, ``"unknown-key-{scope}"``, ``"invalid-value-{scope}"``, ``"duplicate-key-{scope}"``. """def__init__(self,raw_token:str,*,reason:str)->None:"""Construct the error with the offending token and stable reason code. Args: raw_token: The string the operator supplied. reason: Stable reason code (e.g. ``"missing-equals"``, ``"empty-key"``, ``"invalid-value-{scope}"``). """context:dict[str,object]={"reason":reason}key=_safe_token_key(raw_token,flag="--filter")ifkeyisnotNone:context["key"]=keysuper().__init__(context=context,translated_message="review.filter.errors.parse_failed",)self.raw_token=raw_tokenself.safe_token=_safe_token_display(raw_token,flag="--filter")self.reason=reason
def_safe_token_key(raw_token:str,*,flag:str)->str|None:"""Return a parsed token key without exposing the supplied value."""token=raw_token.removeprefix(f"{flag} ").strip()key,separator,_value=token.partition("=")ifnotseparator:returnNonestripped=key.strip().lower()returnstrippedorNonedef_safe_token_display(raw_token:str,*,flag:str)->str:"""Return a CLI-safe token display that never includes the value."""key=_safe_token_key(raw_token,flag=flag)ifkeyisNone:return"<redacted>"returnf"{key}=<redacted>"