Skip to content

Add verbose error logging for failed record operations #190

Closed

Description

@leogdion

Problem

When CloudKit record operations fail (e.g., in batch modifyRecords calls), the RecordInfo structure loses the detailed error information from the CloudKit API response.

Current behavior:

  • CloudKit API returns errors with serverErrorCode and reason fields
  • RecordInfo only exposes: recordName, recordType, recordChangeTag, fields
  • Failed operations set recordType = "Unknown" for error detection via isError property
  • The actual error details (serverErrorCode, reason) are lost

Impact:
When debugging failed CloudKit operations, developers cannot see what went wrong. For example:

  • ACCESS_DENIED errors
  • VALIDATING_REFERENCE_ERROR
  • Schema mismatches
  • Invalid field values

All appear the same: recordType == "Unknown" with no error details.

Proposed Solution

Option 1: Extend RecordInfo to include error details

public struct RecordInfo {
  public let recordName: String
  public let recordType: String
  public let recordChangeTag: String?
  public let fields: [String: FieldValue]
  
  // Add error information
  public let serverErrorCode: String?
  public let reason: String?
  
  public var isError: Bool {
    serverErrorCode != nil
  }
}

Option 2: Add verbose logging in CloudKitResponseProcessor

Log error details before converting to RecordInfo:

internal func processModifyRecordsResponse(_ response: Operations.modifyRecords.Output)
  async throws(CloudKitError) -> Components.Schemas.ModifyResponse
{
  // Log individual record errors before conversion
  if let records = modifyResponse.records {
    for record in records where record.recordType == nil {
      MistKitLogger.logError(
        "Record operation failed - serverErrorCode: \(record.serverErrorCode ?? "unknown"), reason: \(record.reason ?? "unknown")",
        logger: MistKitLogger.api
      )
    }
  }
  
  return modifyResponse
}

Option 3: Add separate error result type

public enum RecordResult {
  case success(RecordInfo)
  case failure(serverErrorCode: String, reason: String, recordName: String?)
}

public func modifyRecords(_ operations: [RecordOperation]) async throws -> [RecordResult]

Use Case

This issue was discovered while debugging BushelCloud sync failures where all 243 RestoreImage records failed with no visible error information, making it impossible to diagnose the root cause.

Priority

Medium - This makes debugging CloudKit integration much harder than necessary.

Activity

  1. coderabbitai commented on Dec 23, 2025

    @coderabbitai

    📝 CodeRabbit Plan Mode

    Generate an implementation plan and prompts that you can use with your favorite coding agent.

    • Create Plan
    Examples

    🔗 Similar Issues

    Related Issues

    🔗 Related PRs

    #132 - Adding Bushel Example [merged]

    👤 Suggested Assignees

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord or schedule a call!

  2. added this to the v1.0.0-alpha.3 milestone on Dec 23, 2025
  3. leogdion commented on Jan 8, 2026

    @leogdion
    MemberAuthor

    ✅ Closing as completed. Comprehensive verbose error logging has been implemented for failed record operations:

    QueryRecords (lines 256-323 in CloudKitService+Operations.swift):

    • Detailed DecodingError logging with key paths, type mismatches, and context
    • Network error logging with error codes and failed URLs
    • Unexpected error logging with type information and reflection

    All Operations:

    • fetchCurrentUser: Full error context logging
    • listZones: Comprehensive error handling
    • modifyRecords: Detailed error information
    • lookupRecords: Complete error diagnostics

    The logging uses MistKitLogger with appropriate subsystems (api, network) and includes shouldRedact flags for privacy control. Error messages provide actionable debugging information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions