feat: add forgejo_error_reporter plugin for automatic error reporting to Forgejo issues

This commit is contained in:
Agent Zero
2026-07-26 12:49:39 +02:00
parent b9d05e2198
commit c3e41906bf
16 changed files with 608 additions and 14 deletions
+15
View File
@@ -19,8 +19,10 @@ logger = logging.getLogger(__name__)
from app.config import get_settings
from app.core.db import close_engine, get_engine
from app.core.error_codes import ApiError
from app.core.middleware import CSRFMiddleware
from app.core.monitoring import record_error, record_request
from app.core.plugin_error_handler import wrap_plugin_route
from app.core.service_container import get_container
from app.plugins.registry import get_registry
from app.routes import (
@@ -325,6 +327,14 @@ def create_app() -> FastAPI:
content={"detail": "Internal server error", "code": "internal_error"},
)
# ── ApiError handler — structured error responses ──
@app.exception_handler(ApiError)
async def api_error_handler(request: Request, exc: ApiError):
return JSONResponse(
status_code=exc.status,
content={'code': exc.code, 'detail': exc.detail, 'field': exc.field}
)
app.include_router(health.router)
app.include_router(metrics.router)
app.include_router(auth.router)
@@ -380,6 +390,7 @@ def create_app() -> FastAPI:
"app.plugins.builtins.mcp_server",
"app.plugins.builtins.system_notif",
"app.plugins.builtins.unified_search",
"app.plugins.builtins.forgejo_error_reporter",
]
for mod_name in plugin_modules:
try:
@@ -392,6 +403,10 @@ def create_app() -> FastAPI:
try:
router_module = importlib.import_module(route_def.module)
router = getattr(router_module, route_def.router_attr)
# Wrap each route handler with plugin error isolation
for route in router.routes:
if hasattr(route, 'endpoint'):
route.endpoint = wrap_plugin_route(route.endpoint)
app.include_router(router)
except Exception as exc:
logger.error(f"Failed to register route {route_def.module}.{route_def.router_attr}: {exc}")