TeraAddUploadCompletion.swift (1408B)
1 import Foundation 2 3 enum TeraAddUploadCompletion { 4 static func complete( 5 _ receipt: TeraAddBackgroundUploadReceipt, 6 handle: TeraPreparedMediaHandle, 7 media _: any TeraAddMediaHandling, 8 runtimeClient: TeraRuntimeClient 9 ) async throws -> TeraDraftStatus { 10 do { 11 return try await runtimeClient.completeAddMediaBackground( 12 input: TeraNativeUploadCompletion( 13 draftID: receipt.draftID, 14 expectedRevision: receipt.expectedRevision, 15 media: handle, 16 statusCode: receipt.statusCode, 17 responseMediaType: receipt.mediaType, 18 responseContentEncoding: receipt.contentEncoding, 19 responseBody: receipt.body 20 ) 21 ) 22 } catch is CancellationError { 23 // Rust completion may already be durable. Leave the receipt awaiting 24 // verification so relaunch can reconcile the unknown outcome. 25 throw CancellationError() 26 } catch { 27 if TeraAddPresentation.failure(for: error)?.code == "ios.runtime.cancelled" { 28 // The bounded runtime client cannot prove whether a cancelled FFI 29 // completion became durable. Preserve the receipt for reconciliation. 30 throw CancellationError() 31 } 32 // Storage failure, timeout, and response rejection cannot establish that 33 // the native attempt is safe to discard. Exact recovery owns that decision. 34 throw error 35 } 36 } 37 }