diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fd93a1..455a026 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Explain EventKit's shared-list move limitation when `edit --list` or `--list-id` fails with ReminderKit error -3002, and direct users to move the reminder in Reminders.app. Thanks @paulchiu. + - Resolve all-digit reminder ID prefixes when the number is outside the current index range, while preserving valid index precedence. Thanks @goutamadwant. - Use the shared Swift CLI release workflow for macOS-only signed releases and no-publish rehearsals, replacing the duplicated release pipeline. diff --git a/README.md b/README.md index 815a0b3..0932892 100644 --- a/README.md +++ b/README.md @@ -301,6 +301,8 @@ If a calendar is missing after `add`, `edit`, or `complete` saves a reminder, th Supporting those would require Apple to expose new public APIs or a separate non-EventKit backend. +Moving reminders with `edit --list` or `edit --list-id` can fail when either list is shared. If EventKit rejects the move with `com.apple.reminderkit error -3002`, move the reminder in Reminders.app, then retry any other edits. `remindctl` does not copy and delete reminders to work around this restriction because EventKit cannot preserve all Reminders.app metadata. + ## Development The package manager is pinned in `package.json`, and `.node-version` selects the docs runtime. diff --git a/Sources/RemindCore/EventKitStore.swift b/Sources/RemindCore/EventKitStore.swift index 06fe009..bd0d9ac 100644 --- a/Sources/RemindCore/EventKitStore.swift +++ b/Sources/RemindCore/EventKitStore.swift @@ -135,6 +135,7 @@ public actor RemindersStore { public func updateReminder(id: String, update: ReminderUpdate) async throws -> ReminderItem { let reminder = try reminder(withID: id) + let originalCalendarID = reminder.calendar?.calendarIdentifier if let title = update.title { reminder.title = title @@ -174,7 +175,9 @@ public actor RemindersStore { reminder.isCompleted = isCompleted } - try eventStore.save(reminder, commit: true) + try ReminderUpdateSave.save(isMoving: reminder.calendar?.calendarIdentifier != originalCalendarID) { + try eventStore.save(reminder, commit: true) + } return try item(from: reminder) } diff --git a/Sources/RemindCore/ReminderUpdateSave.swift b/Sources/RemindCore/ReminderUpdateSave.swift new file mode 100644 index 0000000..16d01e6 --- /dev/null +++ b/Sources/RemindCore/ReminderUpdateSave.swift @@ -0,0 +1,19 @@ +import Foundation + +enum ReminderUpdateSave { + static func save(isMoving: Bool, using save: () throws -> Void) throws { + do { + try save() + } catch { + let failure = error as NSError + guard isMoving, failure.domain == "com.apple.reminderkit", failure.code == -3002 else { + throw error + } + throw RemindCoreError.operationFailed( + "Unable to move reminder between lists: EventKit rejected the move (com.apple.reminderkit error -3002). " + + "Moves involving shared lists may not be supported. Move the reminder in Reminders.app, " + + "then retry any other edits." + ) + } + } +} diff --git a/Tests/RemindCoreTests/ReminderUpdateSaveTests.swift b/Tests/RemindCoreTests/ReminderUpdateSaveTests.swift new file mode 100644 index 0000000..a5422ea --- /dev/null +++ b/Tests/RemindCoreTests/ReminderUpdateSaveTests.swift @@ -0,0 +1,41 @@ +import Foundation +import Testing + +@testable import RemindCore + +struct ReminderUpdateSaveTests { + @Test("A rejected list move explains the shared-list limitation") + func rejectedMove() { + let error = NSError(domain: "com.apple.reminderkit", code: -3002) + #expect(throws: RemindCoreError.operationFailed( + "Unable to move reminder between lists: EventKit rejected the move (com.apple.reminderkit error -3002). " + + "Moves involving shared lists may not be supported. Move the reminder in Reminders.app, " + + "then retry any other edits." + )) { + try ReminderUpdateSave.save(isMoving: true) { throw error } + } + } + + @Test("Unrelated save errors are preserved", arguments: [ + (false, "com.apple.reminderkit", -3002), + (true, "OtherDomain", -3002), + (true, "com.apple.reminderkit", -3001), + ]) + func unrelatedErrors(input: (Bool, String, Int)) { + let (isMoving, domain, code) = input + let original = NSError(domain: domain, code: code, userInfo: [NSLocalizedDescriptionKey: "Original failure"]) + do { + try ReminderUpdateSave.save(isMoving: isMoving) { throw original } + Issue.record("Expected the original save failure") + } catch { + #expect(error as NSError === original) + } + } + + @Test("Successful saves run exactly once", arguments: [true, false]) + func successfulSave(isMoving: Bool) throws { + var calls = 0 + try ReminderUpdateSave.save(isMoving: isMoving) { calls += 1 } + #expect(calls == 1) + } +} diff --git a/docs/commands.md b/docs/commands.md index 2f7b9e1..b822ead 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -73,6 +73,8 @@ remindctl edit 4A83 --list-id 7A12 remindctl edit 4A83 --no-repeat ``` +Moving a reminder with `--list` or `--list-id` can fail when the source or destination list is shared. If EventKit rejects the move with `com.apple.reminderkit error -3002`, move the reminder in Reminders.app, then retry any other edits. The command does not fall back to copying and deleting the reminder, since public EventKit cannot preserve all Reminders.app metadata. + Commands that target reminders accept indexes from the current default listing or ID prefixes. An in-range numeric value always selects that index. An out-of-range numeric value falls back to ID-prefix matching and returns an error when no reminder ID matches. `complete` and `delete` process each reminder once, even when repeated indexes, IDs, or prefixes identify the same reminder. Previews and delete confirmation counts use these unique targets in first-input order; every input must still be valid and unambiguous.