feat: Enhance error handling in note loading and moving operations with detailed logging

This commit is contained in:
2026-05-20 10:05:47 +02:00
parent d0a985b4ab
commit 34f45a912f
2 changed files with 40 additions and 9 deletions
+14 -3
View File
@@ -102,7 +102,9 @@ class _HomeScreenState extends State<HomeScreen> {
_notes = storedNotes;
_isLoading = false;
});
} catch (e) {
} catch (e, st) {
// Log the error so we can inspect the root cause before resetting the vault.
debugPrint('Failed to load notes: $e\n$st');
// If loading notes fails (e.g., DB corrupt), notify the app to reset the vault.
if (widget.onVaultInvalid != null) {
await widget.onVaultInvalid!();
@@ -145,8 +147,17 @@ class _HomeScreenState extends State<HomeScreen> {
final Note movedNote = _notes[oldIndex];
await widget.repository.moveNote(movedNote, newIndex);
await _loadNotes();
try {
await widget.repository.moveNote(movedNote, newIndex);
await _loadNotes();
} catch (e, st) {
// Don't let DB errors cause the app to reset the vault automatically.
debugPrint('Failed to move note: $e\n$st');
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error al reordenar la nota: $e')),
);
}
}
Future<void> _openNoteEditor(Note note) async {