Repository navigation
Commit fa230f3
committed
fix: keep a failed database write from closing the app
MainViewModel launched every action straight in viewModelScope, which has
no exception handler, so a write that threw (a full disk, a broken table)
from a tap took the process down. Every action's launch now takes one
handler that logs and shows a "Something went wrong" toast. Startup
housekeeping logs only, since the user didn't tap anything.
sync() had only try/finally, so a throw there would have left the state
at Syncing with the Sync button disabled until a restart. It now ends as
an error.
New ViewModelActionFailureTest drops the tables under a block, an allow,
a rule add and a rule restore and expects the toast for each; it fails
with the handler removed. A closed database isn't used: Room 2.8 cancels
its scope on close, so the write ends in a CancellationException.1 parent 02badfe commit fa230f3
5 files changed
Lines changed: 238 additions & 112 deletions
File tree
- app/src
- main
- java/com/sysadmindoc/callshield/ui
- res/values
- test/java/com/sysadmindoc/callshield/ui
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
592 | 592 | | |
593 | 593 | | |
594 | 594 | | |
595 | | - | |
| 595 | + | |
596 | 596 | | |
597 | 597 | | |
598 | 598 | | |
599 | 599 | | |
600 | | - | |
| 600 | + | |
601 | 601 | | |
602 | 602 | | |
603 | 603 | | |
| |||
634 | 634 | | |
635 | 635 | | |
636 | 636 | | |
637 | | - | |
638 | | - | |
| 637 | + | |
| 638 | + | |
639 | 639 | | |
640 | 640 | | |
641 | 641 | | |
| |||
0 commit comments