fix: restore graceful fallback in get_default_model and truncate error messages

- Catch ConfigurationError alongside ValueError in get_default_model()
  to preserve graceful fallback after ValueError→ConfigurationError migration
- Add _truncate() helper to error_classifier to cap pass-through and
  default error messages at 200 chars, avoiding verbose internal details
This commit is contained in:
Luis Novo 2026-02-16 16:25:31 -03:00
parent 20e18fdd0d
commit cb5ec9d65c
3 changed files with 11 additions and 4 deletions

View file

@ -80,11 +80,18 @@ def classify_error(exception: BaseException) -> tuple[type[OpenNotebookError], s
for keywords, exc_class, message in _CLASSIFICATION_RULES:
for keyword in keywords:
if keyword in combined:
user_message = message if message is not None else str(exception)
user_message = message if message is not None else _truncate(str(exception))
return exc_class, user_message
# Unclassified error - log for future improvement
logger.warning(
f"Unclassified LLM error ({type(exception).__name__}): {exception}"
)
return ExternalServiceError, f"AI service error: {exception}"
return ExternalServiceError, f"AI service error: {_truncate(str(exception))}"
def _truncate(text: str, max_length: int = 200) -> str:
"""Truncate text to max_length to avoid leaking verbose internal details."""
if len(text) <= max_length:
return text
return text[:max_length] + "..."