Spaces:
Runtime error
Runtime error
Fix syntax error in JSON error handler and ensure error details are escaped safely
Browse filesCorrect a syntax error in the exception handling of finalize_and_doc() that produced invalid Python code in the f-string. The code now uses json.dumps to build a proper JSON error response, eliminating the unexpected character after the line continuation character.
app.py
CHANGED
|
@@ -490,10 +490,12 @@ def finalize_and_doc(chat_history, chat_pairs, sources, plan, chat_key):
|
|
| 490 |
try:
|
| 491 |
json_string = plan_course(chat_history, sources)
|
| 492 |
except Exception as e:
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
|
|
|
|
|
|
| 497 |
# Attempt to parse the JSON to ensure it is valid; if it fails, wrap as raw string
|
| 498 |
try:
|
| 499 |
parsed = json.loads(json_string)
|
|
|
|
| 490 |
try:
|
| 491 |
json_string = plan_course(chat_history, sources)
|
| 492 |
except Exception as e:
|
| 493 |
+
# Construct a minimal JSON error message safely using json.dumps to escape characters
|
| 494 |
+
error_obj = {
|
| 495 |
+
"error": "An error occurred while generating the course outline.",
|
| 496 |
+
"details": str(e),
|
| 497 |
+
}
|
| 498 |
+
json_string = json.dumps(error_obj, indent=2)
|
| 499 |
# Attempt to parse the JSON to ensure it is valid; if it fails, wrap as raw string
|
| 500 |
try:
|
| 501 |
parsed = json.loads(json_string)
|