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 <ethanchang32@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Alvin Tang
2026-03-09 05:39:09 +08:00
committed by GitHub
parent abe865f4f3
commit 2c35bdbcf5
2 changed files with 3 additions and 3 deletions

View File

@@ -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