feat: improve error handling with user-friendly messages (Task 5.3)

- Updated all error messages to be more descriptive and actionable
- Verified error states render correctly in UI (loading, error, empty)
- Confirmed filter handlers check data_loaded before applying filters
- Error handling covers: missing DB, empty DB, SQLite errors, filter errors
This commit is contained in:
Andrew Charlwood
2026-02-04 19:20:57 +00:00
parent 8c04e65ced
commit 6c3b3abf03
2 changed files with 14 additions and 14 deletions
+4 -4
View File
@@ -175,10 +175,10 @@ cd pathways_app && timeout 60 python -m reflex run 2>&1 | head -30
- [ ] Verify smooth 60fps interactions - [ ] Verify smooth 60fps interactions
### 5.3 Error Handling ### 5.3 Error Handling
- [ ] Handle no data loaded state gracefully - [x] Handle no data loaded state gracefully
- [ ] Handle filter resulting in zero records - [x] Handle filter resulting in zero records
- [ ] Handle any data loading errors - [x] Handle any data loading errors
- [ ] User-friendly error messages - [x] User-friendly error messages
### 5.4 Final Verification ### 5.4 Final Verification
- [x] Load real data from SQLite (440K records, 552 drugs, 29 directorates, 32 indications) - [x] Load real data from SQLite (440K records, 552 drugs, 29 directorates, 32 indications)
+10 -10
View File
@@ -403,7 +403,7 @@ class AppState(rx.State):
db_path = Path("data/pathways.db") db_path = Path("data/pathways.db")
if not db_path.exists(): if not db_path.exists():
self.error_message = "Database not found." self.error_message = "Unable to connect to database. Please ensure data has been loaded."
return return
try: try:
@@ -514,9 +514,9 @@ class AppState(rx.State):
self.prepare_chart_data() self.prepare_chart_data()
except sqlite3.Error as e: except sqlite3.Error as e:
self.error_message = f"Database error: {str(e)}" self.error_message = f"Unable to filter data. Database error: {str(e)}"
except Exception as e: except Exception as e:
self.error_message = f"Filter error: {str(e)}" self.error_message = f"An unexpected error occurred while filtering. Details: {str(e)}"
# ========================================================================= # =========================================================================
# Data Loading Methods # Data Loading Methods
@@ -537,7 +537,7 @@ class AppState(rx.State):
db_path = Path("data/pathways.db") db_path = Path("data/pathways.db")
if not db_path.exists(): if not db_path.exists():
self.error_message = "Database not found. Please run data migration first." self.error_message = "Database not found. Please ensure the data has been loaded (data/pathways.db)."
return return
try: try:
@@ -549,7 +549,7 @@ class AppState(rx.State):
self.total_records = cursor.fetchone()[0] self.total_records = cursor.fetchone()[0]
if self.total_records == 0: if self.total_records == 0:
self.error_message = "No data in database. Please run data migration." self.error_message = "The database is empty. No patient records found."
conn.close() conn.close()
return return
@@ -626,10 +626,10 @@ class AppState(rx.State):
self.apply_filters() self.apply_filters()
except sqlite3.Error as e: except sqlite3.Error as e:
self.error_message = f"Database error: {str(e)}" self.error_message = f"Unable to load data. Database error: {str(e)}"
self.data_loaded = False self.data_loaded = False
except Exception as e: except Exception as e:
self.error_message = f"Failed to load data: {str(e)}" self.error_message = f"Failed to load data. Please check the database file. Details: {str(e)}"
self.data_loaded = False self.data_loaded = False
# ========================================================================= # =========================================================================
@@ -663,7 +663,7 @@ class AppState(rx.State):
db_path = Path("data/pathways.db") db_path = Path("data/pathways.db")
if not db_path.exists(): if not db_path.exists():
self.error_message = "Database not found." self.error_message = "Unable to generate chart. Database not found."
self.chart_data = [] self.chart_data = []
return return
@@ -868,11 +868,11 @@ class AppState(rx.State):
self.error_message = "" self.error_message = ""
except sqlite3.Error as e: except sqlite3.Error as e:
self.error_message = f"Chart data error: {str(e)}" self.error_message = f"Unable to generate chart. Database error: {str(e)}"
self.chart_data = [] self.chart_data = []
self.chart_loading = False self.chart_loading = False
except Exception as e: except Exception as e:
self.error_message = f"Chart preparation failed: {str(e)}" self.error_message = f"Unable to generate chart. Details: {str(e)}"
self.chart_data = [] self.chart_data = []
self.chart_loading = False self.chart_loading = False