PageIndex/pageindex/errors.py
Ray 3ff04d501a fix: address max-effort review findings
- clamp LLM-derived page indices in _get_text_of_pages and
  get_text_of_pdf_pages_with_labels; dedupe get_text_of_pdf_pages
- guard _normalize_tree and folders/documents iterations against
  explicit nulls in cloud API responses
- coerce cloud OCR page numbers to int before filtering in
  get_page_content
- folder cache: raise on missing folder id instead of caching None;
  stop caching name-not-found so later lookups can succeed
- defang doc_id in agent doc-context prompt
- append api-key hint to 401 errors (request, legacy and streaming
  paths)
- remove stale legacy JSON workspace sample data unreadable by the
  SQLite storage
2026-07-13 18:49:09 +08:00

64 lines
1.8 KiB
Python

class PageIndexError(Exception):
"""Base exception for all PageIndex SDK errors."""
pass
class CollectionNotFoundError(PageIndexError):
"""Collection does not exist."""
pass
class CollectionAlreadyExistsError(PageIndexError):
"""Collection already exists (create_collection, not get_or_create)."""
pass
class DocumentNotFoundError(PageIndexError):
"""Document ID not found."""
pass
class IndexingError(PageIndexError):
"""Indexing pipeline failure."""
pass
class PageIndexAPIError(PageIndexError):
"""PageIndex cloud API returned an error.
Kept for compatibility with the pageindex 0.2.x cloud SDK.
"""
pass
class CloudAPIError(PageIndexAPIError):
"""Cloud API returned error.
``status_code`` carries the HTTP status when the error came from an HTTP
response (None for transport-level failures), so callers can branch on it
instead of parsing the message.
"""
def __init__(self, message: str, status_code: int | None = None):
super().__init__(message)
self.status_code = status_code
class FileTypeError(PageIndexError, ValueError):
"""Unsupported file type.
Also subclasses ValueError so pre-SDK ``except ValueError`` around indexing
(0.2.x raised ValueError for an unsupported file format) still catches it.
Note: because of this, an ``except ValueError`` clause ahead of an
``except FileTypeError`` clause in the same try block will catch it first —
if you need FileTypeError-specific handling, put that except before (or
instead of) a bare ValueError one.
"""
pass
AUTH_HINT = (
"api_key must be a PageIndex cloud API key (https://dash.pageindex.ai/api-keys). "
"For local mode, omit api_key and set your LLM provider key "
"(e.g. OPENAI_API_KEY) in the environment."
)