From 945c521ed2e08e81434a5b3879c8e68e269109e5 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sun, 23 Aug 2026 19:27:02 +0200 Subject: [PATCH] refac: make the web search error message a plain constant (#28948) The web search error message was a lambda with a passthrough branch that returned whatever it was handed. Since #28942 both call sites pass no arguments, so that branch is unreachable, and it is the trap that let a caller drop a raw exception object into an HTTP response body and turn an intended 400 into an unserialisable 500. A plain string constant removes the trap and lines the message up with every other fixed message in that file. Behaviour is unchanged: the response detail comes out byte for byte identical, because the enum already overrides __str__ to render members as their value. Verified on Python 3.11 and 3.12, both producing the same string and the same JSON body. --- backend/open_webui/constants.py | 2 +- backend/open_webui/routers/retrieval.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/open_webui/constants.py b/backend/open_webui/constants.py index fd61fda228..3ce8d6cf26 100644 --- a/backend/open_webui/constants.py +++ b/backend/open_webui/constants.py @@ -99,7 +99,7 @@ class ERROR_MESSAGES(str, Enum): INVALID_URL = 'The URL you provided is invalid. Please double-check and try again.' - WEB_SEARCH_ERROR = lambda err='': err if err else 'Something went wrong while searching the web.' + WEB_SEARCH_ERROR = 'Something went wrong while searching the web.' OLLAMA_API_DISABLED = 'The Ollama API is disabled. Please enable it to use this feature.' diff --git a/backend/open_webui/routers/retrieval.py b/backend/open_webui/routers/retrieval.py index 97bf35f11b..12d9c23db5 100644 --- a/backend/open_webui/routers/retrieval.py +++ b/backend/open_webui/routers/retrieval.py @@ -2856,7 +2856,7 @@ async def process_web_search(request: Request, form_data: SearchForm, user=Depen log.exception('Web search failed') raise HTTPException( status.HTTP_400_BAD_REQUEST, - detail=ERROR_MESSAGES.DEFAULT(e, ERROR_MESSAGES.WEB_SEARCH_ERROR()), + detail=ERROR_MESSAGES.DEFAULT(e, ERROR_MESSAGES.WEB_SEARCH_ERROR), ) if len(urls) == 0: @@ -2952,7 +2952,7 @@ async def process_web_search(request: Request, form_data: SearchForm, user=Depen log.exception('Web search content loading failed') raise HTTPException( status.HTTP_400_BAD_REQUEST, - detail=ERROR_MESSAGES.DEFAULT(e, ERROR_MESSAGES.WEB_SEARCH_ERROR()), + detail=ERROR_MESSAGES.DEFAULT(e, ERROR_MESSAGES.WEB_SEARCH_ERROR), )