Skip to content

Fix crash risks, race conditions, and silent failures#46

Open
John Dlugokecki (jdlugo) wants to merge 1 commit into
eggerco:mainfrom
jdlugo:claude/confident-herschel
Open

Fix crash risks, race conditions, and silent failures#46
John Dlugokecki (jdlugo) wants to merge 1 commit into
eggerco:mainfrom
jdlugo:claude/confident-herschel

Conversation

@jdlugo

@jdlugo jdlugo commented Mar 15, 2026

Copy link
Copy Markdown

Summary

  • Force unwraps removed: Replace URL(string:)! and Int()! force unwraps with safe unwrapping in 6 files to prevent runtime crashes
  • Race condition fixed: NotificationManager.isNotificationAllowed() was returning synchronously before its async callback completed (always returned false) — now uses async/await
  • BGTask completion fixed: task.setTaskCompleted(success: true) was called immediately before background work finished — now only completes after all refresh tasks are done
  • Keychain duplicate handling: KeychainHelper.save() silently failed on duplicate items — now falls back to SecItemUpdate on errSecDuplicateItem
  • Core Data error logging: PersistenceController.save() silently swallowed save errors — now logs failures via os.Logger

Files changed (9)

  • CronicaApp.swift — BGTask completion timing
  • PersistenceController.swift — Error logging for save()
  • ItemContent-Extensions.swift — 8 force unwraps replaced
  • WatchlistItem-Extension.swift — 1 force unwrap replaced
  • KeychainHelper.swift — Duplicate item handling
  • AccountManager.swift — 1 force unwrap replaced
  • ExternalWatchlistManager.swift — 1 force unwrap replaced
  • NotificationManager.swift — Race condition fix + 1 force unwrap
  • WatchlistButton.swift — 1 force unwrap replaced

Test plan

  • Verify app builds and runs on iOS simulator
  • Test adding/removing items from watchlist (exercises KeychainHelper, PersistenceController, WatchlistButton)
  • Test notification scheduling for upcoming content
  • Verify background refresh completes properly (can monitor via Console.app logs)
  • Confirm Core Data save errors now appear in Console.app logs

🤖 Generated with Claude Code

- Replace force unwraps with safe unwrapping across 6 files (URL construction,
  Int parsing) to prevent runtime crashes
- Fix isNotificationAllowed() race condition: was returning synchronously before
  async callback completed, now uses async/await properly
- Fix BGTask.setTaskCompleted called prematurely before background work finishes;
  now completes only after all refresh tasks are done
- Fix KeychainHelper.save() silently failing on duplicate items by falling back
  to SecItemUpdate when SecItemAdd returns errSecDuplicateItem
- Add error logging to Core Data save() instead of silently swallowing failures

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant