Skip to content

CloudKitSyncEngine.currentAccountId returns nil while peer methods throw accountUnavailable #1034

@datlechin

Description

@datlechin

Follow-up to #1028.

CloudKitSyncEngine has six methods that touch the optional container/database. Five of them (checkAccountStatus, ensureZoneExists, pushBatch, performPull, plus push's wrapping callsite) throw SyncError.accountUnavailable when the entitlement is absent. The sixth, currentAccountId, returns nil instead:

// TablePro/Core/Sync/CloudKitSyncEngine.swift
func currentAccountId() async throws -> String? {
    guard let container else { return nil }
    return try await container.userRecordID().recordName
}

The single caller (`SyncCoordinator.currentAccountId` → `checkAccountStatus` at `TablePro/Core/Sync/SyncCoordinator.swift:632`) wraps it in `try? await`, so both shapes happen to work today. But the inconsistency makes the actor's contract harder to reason about: "missing entitlement" surfaces as two different things depending on which method you call.

Fix

Make currentAccountId throw, matching its peers:

func currentAccountId() async throws -> String? {
    guard let container else { throw SyncError.accountUnavailable }
    return try await container.userRecordID().recordName
}

Flip the matching test in TableProTests/Core/Sync/CloudKitSyncEngineTests.swift from currentAccountIdReturnsNil to expect a throw, mirroring the other five test cases.

The existing try? at the call site stays correct (it already swallows throws).

~5 lines of source + the test rename.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions