Source code for cadrumo.application.corpus_search.errors
"""Typed errors for the on-host corpus-search grounding surface.These are registered :class:`~core.errors.hierarchy.CadrumoError` subclasses, so acorpus-search failure that reaches the CLI boundary renders as its propercategory envelope (a ``REFUSED`` input/dependency refusal, an ``ERROR`` base)rather than collapsing into the generic ``INTERNAL`` unexpected-boundary path.Each class binds one registered ``ErrorCode`` (declared in``core.errors.registry._application_part1``) whose ``message_key`` supplies thelocalized envelope message, and the specifics ride on ``context`` — the samecontextual detail an external adapter may project onto an envelope (the offendingquery/limit/ref). The condition itself travels as a ``reason`` discriminantrather than as a sentence: a free-form constructor message would be preferredby ``str(exc)`` over the registered key, so it would reach tracebacks, logs andevery direct rendering of the exception in English regardless of locale.There is no dependency refusal here: the retrieval surface needs no optionalpackage, so it can never refuse for want of one."""from__future__importannotationsfromcollections.abcimportMappingfrom...core.errors.hierarchyimportCadrumoError
[docs]classCorpusSearchError(CadrumoError):"""Base error for the corpus-search grounding surface."""def__init__(self,*,reason:str,translated_message:str="errors.error.error_corpus_search",context:Mapping[str,object]|None=None,)->None:"""Initialize this public contract."""super().__init__(translated_message=translated_message,context={"reason":reason,**dict(contextor{})})# Preserve the surface's always-a-dict ``context`` contract (CadrumoError's# own base leaves it None when unset); consumers read ``.context`` as a# mapping.self.context={"reason":reason,**dict(contextor{})}self.reason=reason
[docs]classCorpusSearchInputError(CorpusSearchError):"""Raised when a corpus-search request cannot be satisfied. Covers an unknown citation id, a corpus_ref whose backing extracted text is missing, an empty query, and any other caller-supplied input the surface refuses. Which of those it is travels as ``reason``. """def__init__(self,*,reason:str,context:Mapping[str,object]|None=None,)->None:"""Initialize this public contract."""super().__init__(reason=reason,translated_message="errors.refused.refused_corpus_search_input",context=context,)