Skip to content

Fix crash when CloudKit returns records without fields#3

Merged
asabirov merged 1 commit into
main-forkfrom
fix/handle-missing-fields-in-record-lookup
Mar 28, 2026
Merged

Fix crash when CloudKit returns records without fields#3
asabirov merged 1 commit into
main-forkfrom
fix/handle-missing-fields-in-record-lookup

Conversation

@asabirov
Copy link
Copy Markdown
Owner

Summary

  • CloudKit's records/lookup can return records without a fields key (not-found/deleted records), causing a keyNotFound decoding crash
  • Added custom Decodable init for CKRecord that defaults fields to [:] when missing
  • Filter out fieldless records in lookupRecords so get correctly falls through to uniqueIdentifier search
  • Added test target and 7 unit tests covering decoding and BearNote edge cases

Test plan

  • swift test — all 7 tests pass
  • swift run bcli get <invalid-id> — returns clean "Note not found" instead of decoding crash

CloudKit's records/lookup endpoint can return records without a "fields"
key (e.g. not-found or deleted records), causing a keyNotFound decoding
error. This adds a custom Decodable init that defaults fields to an
empty dictionary, and filters out fieldless records from lookupRecords
so the get command correctly falls through to uniqueIdentifier search.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@asabirov asabirov force-pushed the fix/handle-missing-fields-in-record-lookup branch from 84098f4 to 33c0ca5 Compare March 28, 2026 15:28
@asabirov asabirov merged commit b5ed00b into main-fork Mar 28, 2026
asabirov pushed a commit that referenced this pull request Apr 8, 2026
Extract BearCLICore library and add test infrastructure
This was referenced Apr 8, 2026
asabirov added a commit that referenced this pull request Apr 8, 2026
Add custom CKRecord decoder that handles missing/empty fields gracefully
instead of crashing on decode. Add tests for record decoding edge cases.

(reimplements PR #3)
asabirov added a commit that referenced this pull request Apr 8, 2026
Add custom CKRecord decoder that handles missing/empty fields gracefully
instead of crashing on decode. Add tests for record decoding edge cases.

(reimplements PR #3)
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