errors.py 620 Bytes
from __future__ import annotations

import json
from typing import Any


class RagStructuredError(RuntimeError):
    error_code = "RAG_ERROR"

    def __init__(self, message: str, *, detail: dict[str, Any] | None = None) -> None:
        super().__init__(message)
        self.detail = detail or {}

    def to_json(self) -> str:
        return json.dumps({"error_code": self.error_code, **self.detail}, ensure_ascii=False)


class PdfVlmParseError(RagStructuredError):
    """整页 VLM 转写失败(模型不可用、超时、返回为空等)。fail-fast,无兜底。"""
    error_code = "PDF_VLM_PARSE_FAILED"