Improve error extraction: collect all error strings from text encoder response
Browse files- kimodo/model/text_encoder_api.py +15 -24
kimodo/model/text_encoder_api.py
CHANGED
|
@@ -51,31 +51,22 @@ class TextEncoderAPI:
|
|
| 51 |
elif result is not None:
|
| 52 |
candidates = [result]
|
| 53 |
|
|
|
|
| 54 |
for item in candidates:
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
if isinstance(item, dict):
|
| 71 |
-
for key in ("value", "path", "name"):
|
| 72 |
-
value = item.get(key)
|
| 73 |
-
if isinstance(value, str) and value:
|
| 74 |
-
# Check for errors in dict values too
|
| 75 |
-
if value.startswith("##") or "failed" in value.lower() or "error" in value.lower():
|
| 76 |
-
raise RuntimeError(f"Text encoder API error: {value}")
|
| 77 |
-
if value.endswith(".npy"):
|
| 78 |
-
return value
|
| 79 |
|
| 80 |
raise RuntimeError(f"Text encoder API returned unexpected payload: {result!r}")
|
| 81 |
|
|
|
|
| 51 |
elif result is not None:
|
| 52 |
candidates = [result]
|
| 53 |
|
| 54 |
+
# First pass: check for valid .npy paths
|
| 55 |
for item in candidates:
|
| 56 |
+
if isinstance(item, str) and item and item.endswith(".npy"):
|
| 57 |
+
return item
|
| 58 |
+
|
| 59 |
+
# Second pass: collect all error indicators
|
| 60 |
+
error_parts = []
|
| 61 |
+
for item in candidates:
|
| 62 |
+
if isinstance(item, str) and item:
|
| 63 |
+
if item.startswith("##") or "failed" in item.lower() or "error" in item.lower():
|
| 64 |
+
error_parts.append(item.strip())
|
| 65 |
+
|
| 66 |
+
if error_parts:
|
| 67 |
+
# Combine all error messages
|
| 68 |
+
full_error = "\n".join(error_parts)
|
| 69 |
+
raise RuntimeError(f"Text encoder initialization failed:\n{full_error}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
raise RuntimeError(f"Text encoder API returned unexpected payload: {result!r}")
|
| 72 |
|