From 2c35bdbcf5729227a932703f505a9d2aba5b2cd4 Mon Sep 17 00:00:00 2001 From: Alvin Tang <104285249+alvinttang@users.noreply.github.com> Date: Mon, 9 Mar 2026 05:39:09 +0800 Subject: [PATCH] fix: replace bare string raises with proper exception types (#22446) `raise "string"` in Python raises TypeError instead of the intended error, making error messages confusing and debugging difficult. Co-authored-by: gambletan Co-authored-by: Claude Opus 4.6 --- backend/open_webui/retrieval/utils.py | 4 ++-- backend/open_webui/routers/ollama.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/open_webui/retrieval/utils.py b/backend/open_webui/retrieval/utils.py index 86b4acc06d..e19563861b 100644 --- a/backend/open_webui/retrieval/utils.py +++ b/backend/open_webui/retrieval/utils.py @@ -590,7 +590,7 @@ def generate_openai_batch_embeddings( if "data" in data: return [elem["embedding"] for elem in data["data"]] else: - raise "Something went wrong :/" + raise ValueError("Unexpected OpenAI embeddings response: missing 'data' key") except Exception as e: log.exception(f"Error generating openai batch embeddings: {e}") return None @@ -767,7 +767,7 @@ def generate_ollama_batch_embeddings( if "embeddings" in data: return data["embeddings"] else: - raise "Something went wrong :/" + raise ValueError("Unexpected Ollama embeddings response: missing 'embeddings' key") except Exception as e: log.exception(f"Error generating ollama batch embeddings: {e}") return None diff --git a/backend/open_webui/routers/ollama.py b/backend/open_webui/routers/ollama.py index 926e2c02ad..f1170b8f88 100644 --- a/backend/open_webui/routers/ollama.py +++ b/backend/open_webui/routers/ollama.py @@ -1747,7 +1747,7 @@ async def download_file_stream( yield f"data: {json.dumps(res)}\n\n" else: - raise "Ollama: Could not create blob, Please try again." + raise RuntimeError("Ollama: Could not create blob, Please try again.") # url = "https://huggingface.co/TheBloke/stablelm-zephyr-3b-GGUF/resolve/main/stablelm-zephyr-3b.Q2_K.gguf"