handle errors better
This commit is contained in:
25
app.py
25
app.py
@@ -282,6 +282,12 @@ class SessionMoverApp(App):
|
||||
color: $text;
|
||||
}
|
||||
|
||||
#current-selection.error {
|
||||
background: $error;
|
||||
color: $text;
|
||||
text-style: bold;
|
||||
}
|
||||
|
||||
#selection-count {
|
||||
height: auto;
|
||||
padding: 1;
|
||||
@@ -385,10 +391,13 @@ class SessionMoverApp(App):
|
||||
self.db.connect()
|
||||
self.db.load_reference_data()
|
||||
except FileNotFoundError as e:
|
||||
self.notify(str(e), severity="error", timeout=10)
|
||||
self.set_timer(1, self.exit)
|
||||
widget = self.query_one("#current-selection", Static)
|
||||
widget.add_class("error")
|
||||
widget.update(f"Error: {e}\n\nPress q to quit.")
|
||||
self._db_error = True
|
||||
return
|
||||
|
||||
self._db_error = False
|
||||
self._project_ids: List[str] = []
|
||||
self.refresh_project_list()
|
||||
|
||||
@@ -398,15 +407,14 @@ class SessionMoverApp(App):
|
||||
self.query_one("#archived-toggle", Button).can_focus = False
|
||||
|
||||
# Setup sessions table (but don't load data yet)
|
||||
table = self.query_one("#sessions-table")
|
||||
table = self.query_one("#sessions-table", DataTable)
|
||||
table.zebra_stripes = True
|
||||
table.cursor_type = "row"
|
||||
table.show_cursor = False
|
||||
table.add_columns(" ", "ID", "Title", "Project", "Workspace", "Msgs", "Created")
|
||||
|
||||
|
||||
# Don't load sessions until a project is selected
|
||||
status = self.query_one("#current-selection")
|
||||
status.update("Select a project from the left")
|
||||
self.query_one("#current-selection", Static).update("Select a project from the left")
|
||||
|
||||
def on_input_changed(self, event: Input.Changed) -> None:
|
||||
if event.input.id == "filter-input":
|
||||
@@ -655,6 +663,11 @@ class SessionMoverApp(App):
|
||||
self.refresh_sessions()
|
||||
self.notify("Data refreshed", severity="information")
|
||||
|
||||
async def action_quit(self) -> None:
|
||||
"""Exit the app, with a non-zero return code if there was a DB error."""
|
||||
return_code = 1 if getattr(self, "_db_error", False) else 0
|
||||
self.exit(return_code)
|
||||
|
||||
def on_unmount(self) -> None:
|
||||
"""Cleanup on exit."""
|
||||
self.db.close()
|
||||
|
||||
Reference in New Issue
Block a user