"""Plugin error isolation wrapper.""" import logging import functools from fastapi.responses import JSONResponse logger = logging.getLogger(__name__) def wrap_plugin_route(handler): """Decorator that isolates plugin route errors and returns structured JSON.""" @functools.wraps(handler) async def wrapper(*args, **kwargs): try: return await handler(*args, **kwargs) except Exception as exc: logger.error(f'Plugin route error: {exc}', exc_info=True) return JSONResponse( status_code=500, content={'detail': f'Plugin error: {exc}', 'code': 'plugin_error'} ) return wrapper