mirror of
https://github.com/Alishahryar1/free-claude-code.git
synced 2026-06-02 06:13:46 +02:00
Log startup model validation failures clearly
This commit is contained in:
+17
-1
@@ -11,6 +11,7 @@ from fastapi import FastAPI
|
||||
from loguru import logger
|
||||
|
||||
from config.settings import Settings, get_settings
|
||||
from providers.exceptions import ServiceUnavailableError
|
||||
from providers.registry import ProviderRegistry
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -61,6 +62,20 @@ def warn_if_process_auth_token(settings: Settings) -> None:
|
||||
)
|
||||
|
||||
|
||||
def log_startup_failure(settings: Settings, exc: Exception) -> None:
|
||||
"""Log startup failures without traceback noise unless verbose diagnostics are enabled."""
|
||||
if isinstance(exc, ServiceUnavailableError):
|
||||
message = exc.message.strip() or "Server startup failed."
|
||||
logger.error("Startup failed:\n{}", message)
|
||||
return
|
||||
|
||||
if settings.log_api_error_tracebacks:
|
||||
logger.error("Startup failed: {}: {}", type(exc).__name__, exc)
|
||||
return
|
||||
|
||||
logger.error("Startup failed: exc_type={}", type(exc).__name__)
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class AppRuntime:
|
||||
"""Own optional messaging, CLI, session, and provider runtime resources."""
|
||||
@@ -89,7 +104,8 @@ class AppRuntime:
|
||||
await self._provider_registry.validate_configured_models(self.settings)
|
||||
await self._start_messaging_if_configured()
|
||||
self._publish_state()
|
||||
except Exception:
|
||||
except Exception as exc:
|
||||
log_startup_failure(self.settings, exc)
|
||||
await best_effort(
|
||||
"provider_registry.cleanup",
|
||||
self._provider_registry.cleanup(),
|
||||
|
||||
@@ -378,6 +378,7 @@ async def test_runtime_startup_validation_blocks_messaging_and_cleans_up(tmp_pat
|
||||
with (
|
||||
patch.object(ProviderRegistry, "validate_configured_models", new=validation),
|
||||
patch.object(ProviderRegistry, "cleanup", new=cleanup),
|
||||
patch.object(api_runtime_mod.logger, "error") as log_error,
|
||||
patch(
|
||||
"messaging.platforms.factory.create_messaging_platform"
|
||||
) as create_platform,
|
||||
@@ -388,6 +389,12 @@ async def test_runtime_startup_validation_blocks_messaging_and_cleans_up(tmp_pat
|
||||
validation.assert_awaited_once_with(settings)
|
||||
cleanup.assert_awaited_once()
|
||||
create_platform.assert_not_called()
|
||||
logged = " ".join(
|
||||
str(arg) for call in log_error.call_args_list for arg in call.args
|
||||
)
|
||||
assert "Startup failed" in logged
|
||||
assert "bad model" in logged
|
||||
assert "Traceback" not in logged
|
||||
|
||||
|
||||
def test_app_lifespan_messaging_import_error_no_crash(tmp_path, caplog):
|
||||
|
||||
Reference in New Issue
Block a user