Files
mcp-nextcloud/nextcloud_mcp_server/vector/_errors.py
T
Chris CoutinhoandClaude Opus 4.8 0388735593 fix(vector): URL-encode DAV paths and unwrap TaskGroup exceptions
Two ingest-robustness fixes from card 309 (OHR-Bench smoke-test triage).

WebDAV paths flowed through the client already URL-decoded (unquote on the
PROPFIND/REPORT <d:href>, or raw MCP-tool input), so a '#' reached httpx as a
URL fragment and silently truncated the request -> spurious 404 on otherwise
valid files (e.g. law filenames with '#', commas, double/trailing spaces).
Route every caller-path builder through a new _webdav_path helper that
percent-encodes the path once (preserving separators); the MOVE/COPY
Destination header is encoded too.

Vector-sync runs inside anyio task groups, so a child-task failure surfaced as
a BaseExceptionGroup whose str() is the useless "unhandled errors in a
TaskGroup (N sub-exception)" -- hiding the real ConnectError operators need.
Add format_exception_group to flatten the group to its leaf exceptions and use
it at the broad catch/log sites in processor.py and oauth_sync.py.

Refs: Deck board 12 card 309 (AC #4 filename handling, AC #2 observability).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-11 04:59:53 +02:00

37 lines
1.4 KiB
Python

"""Error-formatting helpers for the vector-sync pipeline.
Vector-sync work runs inside anyio task groups, so a failure in a child task
surfaces as a ``BaseExceptionGroup`` whose default ``str()`` is the useless
``"unhandled errors in a TaskGroup (N sub-exception)"`` -- it hides the real
``ConnectError`` / ``APIConnectionError`` that operators need to triage embed
drops (card 309). ``format_exception_group`` flattens the group to the leaf
exceptions so log lines name the actual cause; pair it with ``exc_info=True`` to
keep the full traceback.
"""
from __future__ import annotations
def format_exception_group(exc: BaseException) -> str:
"""Return a concise, leaf-naming string for ``exc``.
For a (possibly nested) ``BaseExceptionGroup`` this joins the ``repr`` of
each leaf exception; for an ordinary exception it returns its ``repr``. The
result is meant for the human-readable portion of a log message, not for
parsing.
"""
leaves = _flatten(exc)
if len(leaves) == 1 and leaves[0] is exc:
return repr(exc)
return f"{len(leaves)} sub-exception(s): " + "; ".join(repr(e) for e in leaves)
def _flatten(exc: BaseException) -> list[BaseException]:
"""Depth-first list of the leaf exceptions within ``exc``."""
if isinstance(exc, BaseExceptionGroup):
leaves: list[BaseException] = []
for sub in exc.exceptions:
leaves.extend(_flatten(sub))
return leaves
return [exc]