From 6c3b3abf03216b0cfb12db24dabb6388db994b83 Mon Sep 17 00:00:00 2001 From: Andrew Charlwood Date: Wed, 4 Feb 2026 19:20:57 +0000 Subject: [PATCH] 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 --- IMPLEMENTATION_PLAN.md | 8 ++++---- pathways_app/app_v2.py | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/IMPLEMENTATION_PLAN.md b/IMPLEMENTATION_PLAN.md index ee33e3c..cc65610 100644 --- a/IMPLEMENTATION_PLAN.md +++ b/IMPLEMENTATION_PLAN.md @@ -175,10 +175,10 @@ cd pathways_app && timeout 60 python -m reflex run 2>&1 | head -30 - [ ] Verify smooth 60fps interactions ### 5.3 Error Handling -- [ ] Handle no data loaded state gracefully -- [ ] Handle filter resulting in zero records -- [ ] Handle any data loading errors -- [ ] User-friendly error messages +- [x] Handle no data loaded state gracefully +- [x] Handle filter resulting in zero records +- [x] Handle any data loading errors +- [x] User-friendly error messages ### 5.4 Final Verification - [x] Load real data from SQLite (440K records, 552 drugs, 29 directorates, 32 indications) diff --git a/pathways_app/app_v2.py b/pathways_app/app_v2.py index bb63ce3..7ed6204 100644 --- a/pathways_app/app_v2.py +++ b/pathways_app/app_v2.py @@ -403,7 +403,7 @@ class AppState(rx.State): db_path = Path("data/pathways.db") 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 try: @@ -514,9 +514,9 @@ class AppState(rx.State): self.prepare_chart_data() 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: - self.error_message = f"Filter error: {str(e)}" + self.error_message = f"An unexpected error occurred while filtering. Details: {str(e)}" # ========================================================================= # Data Loading Methods @@ -537,7 +537,7 @@ class AppState(rx.State): db_path = Path("data/pathways.db") 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 try: @@ -549,7 +549,7 @@ class AppState(rx.State): self.total_records = cursor.fetchone()[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() return @@ -626,10 +626,10 @@ class AppState(rx.State): self.apply_filters() 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 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 # ========================================================================= @@ -663,7 +663,7 @@ class AppState(rx.State): db_path = Path("data/pathways.db") if not db_path.exists(): - self.error_message = "Database not found." + self.error_message = "Unable to generate chart. Database not found." self.chart_data = [] return @@ -868,11 +868,11 @@ class AppState(rx.State): self.error_message = "" 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_loading = False 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_loading = False