Spaces:
Running
Running
Commit
·
c5f9e29
1
Parent(s):
930a207
error printing
Browse files- app.py +6 -1
- utils/error_handler.py +24 -0
app.py
CHANGED
|
@@ -105,7 +105,12 @@ def generate_notebook_route():
|
|
| 105 |
"description": notebook_info["description"]
|
| 106 |
})
|
| 107 |
except Exception as e:
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
@app.route("/prepare_edit_notebook", methods=["POST"])
|
| 111 |
def prepare_edit_notebook():
|
|
|
|
| 105 |
"description": notebook_info["description"]
|
| 106 |
})
|
| 107 |
except Exception as e:
|
| 108 |
+
print(f"Error: Failed to generate notebook: {str(e)}")
|
| 109 |
+
print("Detailed exception information:")
|
| 110 |
+
import traceback
|
| 111 |
+
traceback.print_exc()
|
| 112 |
+
# Still raise the user-friendly message to the UI if needed
|
| 113 |
+
raise Exception("Failed to generate notebook. Please check terminal for details.")
|
| 114 |
|
| 115 |
@app.route("/prepare_edit_notebook", methods=["POST"])
|
| 116 |
def prepare_edit_notebook():
|
utils/error_handler.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import traceback
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
# Configure logging to output to terminal
|
| 6 |
+
logging.basicConfig(
|
| 7 |
+
level=logging.DEBUG,
|
| 8 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
| 9 |
+
stream=sys.stderr
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
logger = logging.getLogger('NoteGenie')
|
| 13 |
+
|
| 14 |
+
def handle_error(func):
|
| 15 |
+
"""Decorator to handle exceptions and log them to terminal"""
|
| 16 |
+
def wrapper(*args, **kwargs):
|
| 17 |
+
try:
|
| 18 |
+
return func(*args, **kwargs)
|
| 19 |
+
except Exception as e:
|
| 20 |
+
logger.error(f"Error in {func.__name__}: {str(e)}")
|
| 21 |
+
logger.error(traceback.format_exc())
|
| 22 |
+
# You can still raise a user-friendly error for the UI
|
| 23 |
+
raise Exception("Failed to generate notebook. Please check terminal for details.")
|
| 24 |
+
return wrapper
|