Skip to content

Commit c396933

Browse files
Merge pull request #87 from ably/48-get-rid-of-InternalError
Remove InternalError
2 parents 41c319b + 5ba838b commit c396933

26 files changed

+350
-362
lines changed

AblyLiveObjects.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let package = Package(
2121
.package(
2222
url: "https://github.com/ably/ably-cocoa",
2323
// TODO: Unpin before next release
24-
revision: "8dde3e841aa1f861176c1341cf44e92014b95857",
24+
revision: "6bcbf5faaa7b577f4fe8129d895be0f24258aa27",
2525
),
2626
.package(
2727
url: "https://github.com/ably/ably-cocoa-plugin-support",

Sources/AblyLiveObjects/Internal/CoreSDK.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import Ably
66
/// This provides us with a mockable interface to ably-cocoa, and it also allows internal components and their tests not to need to worry about some of the boring details of how we bridge Swift types to `_AblyPluginSupportPrivate`'s Objective-C API (i.e. boxing).
77
internal protocol CoreSDK: AnyObject, Sendable {
88
/// Implements the internal `#publish` method of RTO15.
9-
func publish(objectMessages: [OutboundObjectMessage]) async throws(InternalError)
9+
func publish(objectMessages: [OutboundObjectMessage]) async throws(ARTErrorInfo)
1010

1111
/// Replaces the implementation of ``publish(objectMessages:)``.
1212
///
1313
/// Used by integration tests, for example to disable `ObjectMessage` publishing so that a test can verify that a behaviour is not a side effect of an `ObjectMessage` sent by the SDK.
14-
func testsOnly_overridePublish(with newImplementation: @escaping ([OutboundObjectMessage]) async throws(InternalError) -> Void)
14+
func testsOnly_overridePublish(with newImplementation: @escaping ([OutboundObjectMessage]) async throws(ARTErrorInfo) -> Void)
1515

1616
/// Returns the current state of the Realtime channel that this wraps.
1717
var nosync_channelState: _AblyPluginSupportPrivate.RealtimeChannelState { get }
@@ -30,7 +30,7 @@ internal final class DefaultCoreSDK: CoreSDK {
3030
///
3131
/// This enables the `testsOnly_overridePublish(with:)` test hook.
3232
///
33-
/// - Note: This should be `throws(InternalError)` but that causes a compilation error of "Runtime support for typed throws function types is only available in macOS 15.0.0 or newer".
33+
/// - Note: This should be `throws(ARTErrorInfo)` but that causes a compilation error of "Runtime support for typed throws function types is only available in macOS 15.0.0 or newer".
3434
private nonisolated(unsafe) var overriddenPublishImplementation: (([OutboundObjectMessage]) async throws -> Void)?
3535

3636
internal init(
@@ -47,7 +47,7 @@ internal final class DefaultCoreSDK: CoreSDK {
4747

4848
// MARK: - CoreSDK conformance
4949

50-
internal func publish(objectMessages: [OutboundObjectMessage]) async throws(InternalError) {
50+
internal func publish(objectMessages: [OutboundObjectMessage]) async throws(ARTErrorInfo) {
5151
logger.log("publish(objectMessages: \(LoggingUtilities.formatObjectMessagesForLogging(objectMessages)))", level: .debug)
5252

5353
// Use the overridden implementation if supplied
@@ -58,10 +58,10 @@ internal final class DefaultCoreSDK: CoreSDK {
5858
do {
5959
try await overriddenImplementation(objectMessages)
6060
} catch {
61-
guard let internalError = error as? InternalError else {
62-
preconditionFailure("Expected InternalError, got \(error)")
61+
guard let artErrorInfo = error as? ARTErrorInfo else {
62+
preconditionFailure("Expected ARTErrorInfo, got \(error)")
6363
}
64-
throw internalError
64+
throw artErrorInfo
6565
}
6666
return
6767
}
@@ -75,7 +75,7 @@ internal final class DefaultCoreSDK: CoreSDK {
7575
)
7676
}
7777

78-
internal func testsOnly_overridePublish(with newImplementation: @escaping ([OutboundObjectMessage]) async throws(InternalError) -> Void) {
78+
internal func testsOnly_overridePublish(with newImplementation: @escaping ([OutboundObjectMessage]) async throws(ARTErrorInfo) -> Void) {
7979
mutex.withLock {
8080
overriddenPublishImplementation = newImplementation
8181
}

Sources/AblyLiveObjects/Internal/DefaultInternalPlugin.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ internal final class DefaultInternalPlugin: NSObject, _AblyPluginSupportPrivate.
8787
)
8888
return ObjectMessageBox(objectMessage: objectMessage)
8989
} catch {
90-
errorPtr?.pointee = error.toARTErrorInfo().asPluginPublicErrorInfo
90+
errorPtr?.pointee = error.asPluginPublicErrorInfo
9191
return nil
9292
}
9393
}
@@ -140,10 +140,10 @@ internal final class DefaultInternalPlugin: NSObject, _AblyPluginSupportPrivate.
140140
channel: _AblyPluginSupportPrivate.RealtimeChannel,
141141
client: _AblyPluginSupportPrivate.RealtimeClient,
142142
pluginAPI: PluginAPIProtocol,
143-
) async throws(InternalError) {
143+
) async throws(ARTErrorInfo) {
144144
let objectMessageBoxes: [ObjectMessageBox<OutboundObjectMessage>] = objectMessages.map { .init(objectMessage: $0) }
145145

146-
try await withCheckedContinuation { (continuation: CheckedContinuation<Result<Void, InternalError>, _>) in
146+
try await withCheckedContinuation { (continuation: CheckedContinuation<Result<Void, ARTErrorInfo>, _>) in
147147
let internalQueue = pluginAPI.internalQueue(for: client)
148148

149149
internalQueue.async {
@@ -155,7 +155,7 @@ internal final class DefaultInternalPlugin: NSObject, _AblyPluginSupportPrivate.
155155
dispatchPrecondition(condition: .onQueue(internalQueue))
156156

157157
if let error {
158-
continuation.resume(returning: .failure(error.toInternalError()))
158+
continuation.resume(returning: .failure(ARTErrorInfo.castPluginPublicErrorInfo(error)))
159159
} else {
160160
continuation.resume(returning: .success(()))
161161
}

Sources/AblyLiveObjects/Internal/InternalDefaultLiveCounter.swift

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -104,42 +104,34 @@ internal final class InternalDefaultLiveCounter: Sendable {
104104
}
105105

106106
internal func increment(amount: Double, coreSDK: CoreSDK) async throws(ARTErrorInfo) {
107-
do throws(InternalError) {
108-
let objectMessage = try mutableStateMutex.withSync { mutableState throws(InternalError) in
109-
// RTLC12c
110-
do throws(ARTErrorInfo) {
111-
try coreSDK.nosync_validateChannelState(
112-
notIn: [.detached, .failed, .suspended],
113-
operationDescription: "LiveCounter.increment",
114-
)
115-
} catch {
116-
throw error.toInternalError()
117-
}
118-
119-
// RTLC12e1
120-
if !amount.isFinite {
121-
throw LiveObjectsError.counterIncrementAmountInvalid(amount: amount).toARTErrorInfo().toInternalError()
122-
}
107+
let objectMessage = try mutableStateMutex.withSync { mutableState throws(ARTErrorInfo) in
108+
// RTLC12c
109+
try coreSDK.nosync_validateChannelState(
110+
notIn: [.detached, .failed, .suspended],
111+
operationDescription: "LiveCounter.increment",
112+
)
123113

124-
return OutboundObjectMessage(
125-
operation: .init(
126-
// RTLC12e2
127-
action: .known(.counterInc),
128-
// RTLC12e3
129-
objectId: mutableState.liveObjectMutableState.objectID,
130-
counterOp: .init(
131-
// RTLC12e4
132-
amount: .init(value: amount),
133-
),
134-
),
135-
)
114+
// RTLC12e1
115+
if !amount.isFinite {
116+
throw LiveObjectsError.counterIncrementAmountInvalid(amount: amount).toARTErrorInfo()
136117
}
137118

138-
// RTLC12f
139-
try await coreSDK.publish(objectMessages: [objectMessage])
140-
} catch {
141-
throw error.toARTErrorInfo()
119+
return OutboundObjectMessage(
120+
operation: .init(
121+
// RTLC12e2
122+
action: .known(.counterInc),
123+
// RTLC12e3
124+
objectId: mutableState.liveObjectMutableState.objectID,
125+
counterOp: .init(
126+
// RTLC12e4
127+
amount: .init(value: amount),
128+
),
129+
),
130+
)
142131
}
132+
133+
// RTLC12f
134+
try await coreSDK.publish(objectMessages: [objectMessage])
143135
}
144136

145137
internal func decrement(amount: Double, coreSDK: CoreSDK) async throws(ARTErrorInfo) {

Sources/AblyLiveObjects/Internal/InternalDefaultLiveMap.swift

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -150,66 +150,50 @@ internal final class InternalDefaultLiveMap: Sendable {
150150
}
151151

152152
internal func set(key: String, value: InternalLiveMapValue, coreSDK: CoreSDK) async throws(ARTErrorInfo) {
153-
do throws(InternalError) {
154-
let objectMessage = try mutableStateMutex.withSync { mutableState throws(InternalError) in
155-
// RTLM20c
156-
do throws(ARTErrorInfo) {
157-
try coreSDK.nosync_validateChannelState(notIn: [.detached, .failed, .suspended], operationDescription: "LiveMap.set")
158-
} catch {
159-
throw error.toInternalError()
160-
}
161-
162-
return OutboundObjectMessage(
163-
operation: .init(
164-
// RTLM20e2
165-
action: .known(.mapSet),
166-
// RTLM20e3
167-
objectId: mutableState.liveObjectMutableState.objectID,
168-
mapOp: .init(
169-
// RTLM20e4
170-
key: key,
171-
// RTLM20e5
172-
data: value.nosync_toObjectData,
173-
),
153+
let objectMessage = try mutableStateMutex.withSync { mutableState throws(ARTErrorInfo) in
154+
// RTLM20c
155+
try coreSDK.nosync_validateChannelState(notIn: [.detached, .failed, .suspended], operationDescription: "LiveMap.set")
156+
157+
return OutboundObjectMessage(
158+
operation: .init(
159+
// RTLM20e2
160+
action: .known(.mapSet),
161+
// RTLM20e3
162+
objectId: mutableState.liveObjectMutableState.objectID,
163+
mapOp: .init(
164+
// RTLM20e4
165+
key: key,
166+
// RTLM20e5
167+
data: value.nosync_toObjectData,
174168
),
175-
)
176-
}
177-
178-
try await coreSDK.publish(objectMessages: [objectMessage])
179-
} catch {
180-
throw error.toARTErrorInfo()
169+
),
170+
)
181171
}
172+
173+
try await coreSDK.publish(objectMessages: [objectMessage])
182174
}
183175

184176
internal func remove(key: String, coreSDK: CoreSDK) async throws(ARTErrorInfo) {
185-
do throws(InternalError) {
186-
let objectMessage = try mutableStateMutex.withSync { mutableState throws(InternalError) in
187-
// RTLM21c
188-
do throws(ARTErrorInfo) {
189-
try coreSDK.nosync_validateChannelState(notIn: [.detached, .failed, .suspended], operationDescription: "LiveMap.remove")
190-
} catch {
191-
throw error.toInternalError()
192-
}
193-
194-
return OutboundObjectMessage(
195-
operation: .init(
196-
// RTLM21e2
197-
action: .known(.mapRemove),
198-
// RTLM21e3
199-
objectId: mutableState.liveObjectMutableState.objectID,
200-
mapOp: .init(
201-
// RTLM21e4
202-
key: key,
203-
),
177+
let objectMessage = try mutableStateMutex.withSync { mutableState throws(ARTErrorInfo) in
178+
// RTLM21c
179+
try coreSDK.nosync_validateChannelState(notIn: [.detached, .failed, .suspended], operationDescription: "LiveMap.remove")
180+
181+
return OutboundObjectMessage(
182+
operation: .init(
183+
// RTLM21e2
184+
action: .known(.mapRemove),
185+
// RTLM21e3
186+
objectId: mutableState.liveObjectMutableState.objectID,
187+
mapOp: .init(
188+
// RTLM21e4
189+
key: key,
204190
),
205-
)
206-
}
207-
208-
// RTLM21f
209-
try await coreSDK.publish(objectMessages: [objectMessage])
210-
} catch {
211-
throw error.toARTErrorInfo()
191+
),
192+
)
212193
}
194+
195+
// RTLM21f
196+
try await coreSDK.publish(objectMessages: [objectMessage])
213197
}
214198

215199
@discardableResult

0 commit comments

Comments
 (0)