Skip to content

Commit 77f3dca

Browse files
committed
fix: a failed add reported itself as "Task Added Successfully"
addTaskToReplica and deleteTaskFromReplica answered with an "scc"/"err" sentinel that no caller read. The consequences differ by call site: - the add sheet discarded the result and showed the success snackbar unconditionally, cleared the form and closed itself. A refused write told the user the task had been added and threw away what they had typed - swipe-to-complete and swipe-to-delete discarded it too and refreshed the list either way, so a failure looked like the swipe had not registered Both now return null on success or the reason, matching modifyTaskInReplica, which already did this. The prefix-stripping that turns an FFI error into something readable moves into one `_reason` helper rather than being written out at each catch. The add sheet stays open with the input intact when a write is refused, since the task really is still unsaved. This matters more now than it did: update_task and add_task refuse a repeating task with no due date, and add_task refuses an unknown status or attribute. Those refusals carry an explanation, and until now the two paths that could provoke one had nowhere to put it. Tested: 417 Dart tests pass (unchanged baseline), analyze reports no new warnings. Verified on device that adding, swipe-completing and swipe-deleting all still work and show no spurious error.
1 parent f40ba5f commit 77f3dca

3 files changed

Lines changed: 68 additions & 16 deletions

File tree

‎lib/app/modules/home/views/add_task_bottom_sheet_new.dart‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@ class AddTaskBottomSheet extends StatelessWidget {
458458
void onSaveButtonClickedForReplica(BuildContext context) async {
459459
if (homeController.formKey.currentState!.validate()) {
460460
try {
461-
await Replica.addTaskToReplica(HashMap<String, dynamic>.from({
461+
final String? error =
462+
await Replica.addTaskToReplica(HashMap<String, dynamic>.from({
462463
"description": homeController.namecontroller.text.trim(),
463464
"due": getDueDate(homeController.selectedDates)?.toUtc(),
464465
"priority": homeController.priority.value,
@@ -468,6 +469,25 @@ class AddTaskBottomSheet extends StatelessWidget {
468469
"wait": getWaitDate(homeController.selectedDates)?.toUtc(),
469470
"tags": homeController.tags,
470471
}));
472+
if (error != null) {
473+
// The result used to be discarded and the success message shown
474+
// regardless, so a refused write still reported the task as added.
475+
// Leave the sheet open with the input intact — it is still unsaved.
476+
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
477+
content: Text(
478+
error,
479+
style: TextStyle(
480+
color: AppSettings.isDarkMode
481+
? TaskWarriorColors.kprimaryTextColor
482+
: TaskWarriorColors.kLightPrimaryTextColor,
483+
),
484+
),
485+
backgroundColor: AppSettings.isDarkMode
486+
? TaskWarriorColors.ksecondaryBackgroundColor
487+
: TaskWarriorColors.kLightSecondaryBackgroundColor,
488+
duration: const Duration(seconds: 4)));
489+
return;
490+
}
471491
homeController.namecontroller.text = '';
472492
homeController.projectcontroller.text = '';
473493
homeController.dueString.value = "";

‎lib/app/modules/home/views/show_tasks_replica.dart‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,29 @@ class TaskReplicaViewBuilder extends StatelessWidget {
274274
}
275275
}
276276

277+
// Both of these used to discard the result. A refused write left the task
278+
// exactly where it was with no explanation, which reads as the swipe simply
279+
// not having registered.
277280
void completeTask(TaskForReplica task) async {
278-
await Replica.modifyTaskInReplica(task.copyWith(status: 'completed'));
281+
final String? error =
282+
await Replica.modifyTaskInReplica(task.copyWith(status: 'completed'));
283+
if (error != null) {
284+
Get.snackbar('Not completed', error,
285+
snackPosition: SnackPosition.BOTTOM,
286+
duration: const Duration(seconds: 4));
287+
return;
288+
}
279289
Get.find<HomeController>().refreshReplicaTaskList();
280290
}
281291

282292
void deleteTask(TaskForReplica task) async {
283-
await Replica.deleteTaskFromReplica(task.uuid);
293+
final String? error = await Replica.deleteTaskFromReplica(task.uuid);
294+
if (error != null) {
295+
Get.snackbar('Not deleted', error,
296+
snackPosition: SnackPosition.BOTTOM,
297+
duration: const Duration(seconds: 4));
298+
return;
299+
}
284300
Get.find<HomeController>().refreshReplicaTaskList();
285301
}
286302
}

‎lib/app/v3/champion/replica.dart‎

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@ class Replica {
2525
// interprets. The desktop CLI is what acts on it.
2626
"recur",
2727
];
28-
static Future<String> addTaskToReplica(
28+
/// Create a task, returning null on success or the reason it was refused.
29+
///
30+
/// This used to answer with a success/failure sentinel that no caller read —
31+
/// the add sheet announced success unconditionally, so a rejected write still
32+
/// told the user the task had been added. Matches modifyTaskInReplica.
33+
static Future<String?> addTaskToReplica(
2934
HashMap<String, dynamic> newTask) async {
3035
var taskdbDirPath = await getReplicaPath();
3136
HashMap<String, String> map = HashMap<String, String>();
3237
if (newTask.containsKey("uuid") && newTask['uuid'].isEmpty) {
33-
return "err";
38+
return "This task has no identifier yet.";
3439
}
3540
String tags = "";
3641
if (newTask['tags'] != null && (newTask['tags'] as List).isNotEmpty) {
@@ -51,9 +56,9 @@ class Replica {
5156
} catch (e, s) {
5257
debugPrint(e.toString());
5358
debugPrint(s.toString());
54-
return "err";
59+
return _reason(e);
5560
}
56-
return "scc";
61+
return null;
5762
}
5863

5964
/// Apply an edit to a replica task.
@@ -84,15 +89,23 @@ class Replica {
8489
} catch (e, s) {
8590
debugPrint(e.toString());
8691
debugPrint(s.toString());
87-
final String raw = e.toString();
88-
final int marker = raw.indexOf(': ');
89-
return marker >= 0 && marker + 2 < raw.length
90-
? raw.substring(marker + 2)
91-
: raw;
92+
return _reason(e);
9293
}
9394
return null;
9495
}
9596

97+
/// The human-readable half of an FFI error.
98+
///
99+
/// The Rust side reports why a write was refused; flutter_rust_bridge hands
100+
/// it over prefixed with the error variant, which is noise to the user.
101+
static String _reason(Object e) {
102+
final String raw = e.toString();
103+
final int marker = raw.indexOf(': ');
104+
return marker >= 0 && marker + 2 < raw.length
105+
? raw.substring(marker + 2)
106+
: raw;
107+
}
108+
96109
/// Attach a note to a task, returning the entry timestamp that identifies it.
97110
///
98111
/// Unlike the older helpers here, this deliberately lets the FFI error
@@ -145,14 +158,17 @@ class Replica {
145158
);
146159
}
147160

148-
static Future<String> deleteTaskFromReplica(String uuid) async {
161+
/// Soft-delete a task, returning null on success or the reason it failed.
162+
static Future<String?> deleteTaskFromReplica(String uuid) async {
149163
var taskdbDirPath = await getReplicaPath();
150164
try {
151165
await deleteTask(uuidSt: uuid, taskdbDirPath: taskdbDirPath);
152-
} catch (e) {
153-
return "err";
166+
} catch (e, s) {
167+
debugPrint(e.toString());
168+
debugPrint(s.toString());
169+
return _reason(e);
154170
}
155-
return "scc";
171+
return null;
156172
}
157173

158174
static Future<List<TaskForReplica>> getAllTasksFromReplica() async {

0 commit comments

Comments
 (0)