mirror of
https://github.com/lfnovo/open-notebook.git
synced 2026-04-29 03:50:04 +00:00
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:
parent
20e18fdd0d
commit
cb5ec9d65c
3 changed files with 11 additions and 4 deletions
|
|
@ -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] + "..."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue