debug: add /debug/routers endpoint to diagnose import failures
Some checks failed
CI/CD / go-lint (push) Has been skipped
CI/CD / python-lint (push) Has been skipped
CI/CD / nodejs-lint (push) Has been skipped
CI/CD / test-go-ai-compliance (push) Failing after 32s
CI/CD / test-python-backend-compliance (push) Successful in 1m37s
CI/CD / test-python-document-crawler (push) Successful in 20s
CI/CD / test-python-dsms-gateway (push) Successful in 17s
CI/CD / validate-canonical-controls (push) Successful in 10s
CI/CD / Deploy (push) Has been skipped
Some checks failed
CI/CD / go-lint (push) Has been skipped
CI/CD / python-lint (push) Has been skipped
CI/CD / nodejs-lint (push) Has been skipped
CI/CD / test-go-ai-compliance (push) Failing after 32s
CI/CD / test-python-backend-compliance (push) Successful in 1m37s
CI/CD / test-python-document-crawler (push) Successful in 20s
CI/CD / test-python-dsms-gateway (push) Successful in 17s
CI/CD / validate-canonical-controls (push) Successful in 10s
CI/CD / Deploy (push) Has been skipped
Crosswalk routes returning 404 on production. This adds a diagnostic endpoint that reports which sub-routers failed to load and why. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,8 @@ from .routes import router
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
_failed_routers: dict[str, str] = {}
|
||||||
|
|
||||||
|
|
||||||
def _safe_import_router(module_name: str, attr: str = "router"):
|
def _safe_import_router(module_name: str, attr: str = "router"):
|
||||||
"""Import a router module safely — log error but don't crash the whole app."""
|
"""Import a router module safely — log error but don't crash the whole app."""
|
||||||
@@ -14,6 +16,7 @@ def _safe_import_router(module_name: str, attr: str = "router"):
|
|||||||
return getattr(mod, attr)
|
return getattr(mod, attr)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Failed to import %s: %s", module_name, e)
|
logger.error("Failed to import %s: %s", module_name, e)
|
||||||
|
_failed_routers[module_name] = str(e)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,18 @@ async def health():
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/debug/routers", tags=["system"])
|
||||||
|
async def debug_routers():
|
||||||
|
"""Diagnostic: show which sub-routers loaded and which failed."""
|
||||||
|
from compliance.api import _ROUTER_MODULES, _failed_routers, _loaded_count
|
||||||
|
return {
|
||||||
|
"total": len(_ROUTER_MODULES),
|
||||||
|
"loaded": _loaded_count,
|
||||||
|
"failed_count": len(_failed_routers),
|
||||||
|
"failed": _failed_routers,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# --- Compliance-specific Routers ---
|
# --- Compliance-specific Routers ---
|
||||||
|
|
||||||
# Consent (user-facing)
|
# Consent (user-facing)
|
||||||
|
|||||||
Reference in New Issue
Block a user