Skip to content

Commit 76c368f

Browse files
committed
Merge remote-tracking branch 'origin/main' into 1-add-documentation-comments
# Conflicts: # Sources/AblyChat/Errors.swift # Sources/AblyChat/Rooms.swift
2 parents 33b4b5e + b436fe5 commit 76c368f

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

Example/AblyChatExample/Mocks/MockClients.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ actor MockRooms: Rooms {
3232
return room
3333
}
3434

35-
func release(roomID _: String) async throws {
35+
func release(roomID _: String) async {
3636
fatalError("Not yet implemented")
3737
}
3838

Sources/AblyChat/Errors.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ public let errorDomain = "AblyChatErrorDomain"
1111
The error codes for errors in the ``errorDomain`` error domain.
1212
*/
1313
public enum ErrorCode: Int {
14-
/// ``Rooms/get(roomID:options:)`` was called with a different set of room options than was used on a previous call. You must first release the existing room instance using ``Rooms/release(roomID:)``.
15-
///
16-
/// TODO this code is a guess, revisit in https://github.com/ably-labs/ably-chat-swift/issues/32
17-
case inconsistentRoomOptions = 1
14+
/// The user attempted to perform an invalid action.
15+
case badRequest = 40000
1816

1917
/**
2018
* The messages feature failed to attach.
@@ -90,7 +88,7 @@ public enum ErrorCode: Int {
9088

9189
/// Has a case for each of the ``ErrorCode`` cases that imply a fixed status code.
9290
internal enum CaseThatImpliesFixedStatusCode {
93-
case inconsistentRoomOptions
91+
case badRequest
9492
case messagesAttachmentFailed
9593
case presenceAttachmentFailed
9694
case reactionsAttachmentFailed
@@ -108,8 +106,8 @@ public enum ErrorCode: Int {
108106

109107
internal var toNumericErrorCode: ErrorCode {
110108
switch self {
111-
case .inconsistentRoomOptions:
112-
.inconsistentRoomOptions
109+
case .badRequest:
110+
.badRequest
113111
case .messagesAttachmentFailed:
114112
.messagesAttachmentFailed
115113
case .presenceAttachmentFailed:
@@ -145,7 +143,7 @@ public enum ErrorCode: Int {
145143
internal var statusCode: Int {
146144
// These status codes are taken from the "Chat-specific Error Codes" section of the spec.
147145
switch self {
148-
case .inconsistentRoomOptions,
146+
case .badRequest,
149147
.roomInFailedState,
150148
.roomIsReleasing,
151149
.roomIsReleased,
@@ -227,7 +225,7 @@ internal enum ChatError {
227225
internal var codeAndStatusCode: ErrorCodeAndStatusCode {
228226
switch self {
229227
case .inconsistentRoomOptions:
230-
.fixedStatusCode(.inconsistentRoomOptions)
228+
.fixedStatusCode(.badRequest)
231229
case let .attachmentFailed(feature, _):
232230
switch feature {
233231
case .messages:

Sources/AblyChat/Rooms.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public protocol Rooms: AnyObject, Sendable {
4040
* - Parameters:
4141
* - roomID: The ID of the room.
4242
*/
43-
func release(roomID: String) async throws
43+
func release(roomID: String) async
4444

4545
/**
4646
* Get the client options used to create the chat instance.
@@ -302,7 +302,7 @@ internal actor DefaultRooms<RoomFactory: AblyChat.RoomFactory>: Rooms {
302302
}
303303
#endif
304304

305-
internal func release(roomID: String) async throws {
305+
internal func release(roomID: String) async {
306306
guard let roomState = roomStates[roomID] else {
307307
// CHA-RC1g2 (no-op)
308308
return

Tests/AblyChatTests/DefaultRoomsTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ struct DefaultRoomsTests {
143143
_ = try await rooms.get(roomID: roomID, options: options)
144144

145145
// When: get(roomID:options:) is called with the same ID but different options
146-
// Then: It throws an inconsistentRoomOptions error
146+
// Then: It throws a `badRequest` error
147147
let differentOptions = RoomOptions(presence: .init(subscribe: false))
148148

149149
await #expect {
150150
try await rooms.get(roomID: roomID, options: differentOptions)
151151
} throws: { error in
152-
isChatError(error, withCodeAndStatusCode: .fixedStatusCode(.inconsistentRoomOptions))
152+
isChatError(error, withCodeAndStatusCode: .fixedStatusCode(.badRequest))
153153
}
154154
}
155155

@@ -183,13 +183,13 @@ struct DefaultRoomsTests {
183183
_ = await operationWaitSubscription.first { $0.waitingOperationType == .get && $0.waitedOperationType == .release }
184184

185185
// When: get(roomID:options:) is called with the same ID but different options
186-
// Then: The second call to get(roomID:options:) throws an inconsistentRoomOptions error
186+
// Then: The second call to get(roomID:options:) throws a `badRequest` error
187187
let differentOptions = RoomOptions(presence: .init(subscribe: false))
188188

189189
await #expect {
190190
try await rooms.get(roomID: roomID, options: differentOptions)
191191
} throws: { error in
192-
isChatError(error, withCodeAndStatusCode: .fixedStatusCode(.inconsistentRoomOptions))
192+
isChatError(error, withCodeAndStatusCode: .fixedStatusCode(.badRequest))
193193
}
194194

195195
// Post-test: Allow the CHA-RC1g release operation to complete
@@ -251,7 +251,7 @@ struct DefaultRoomsTests {
251251
// When: `release(roomID:)` is called with this room ID
252252
// Then: The call to `release(roomID:)` completes (this is as much as I can do to test the spec’s “no-op”; i.e. check it doesn’t seem to wait for anything or have any obvious side effects)
253253
let roomID = "basketball"
254-
try await rooms.release(roomID: roomID)
254+
await rooms.release(roomID: roomID)
255255
}
256256

257257
// @spec CHA-RC1g3
@@ -290,7 +290,7 @@ struct DefaultRoomsTests {
290290
roomReleaseOperation.complete()
291291

292292
// Then: The second call to `release(roomID:)` completes, and this second release call does not trigger a CHA-RL3 room release operation (i.e. in the language of the spec it reuses the “future” of the existing CHA-RC1g release operation)
293-
try await secondReleaseResult
293+
await secondReleaseResult
294294
#expect(await roomToReturn.releaseCallCount == 1)
295295
}
296296

@@ -344,7 +344,7 @@ struct DefaultRoomsTests {
344344
roomReleaseOperation.complete()
345345

346346
// Then: The second call to `release(roomID:)` completes, and this second release call does not trigger a CHA-RL3 room release operation (i.e. in the language of the spec it reuses the “future” of the existing CHA-RC1g release operation)
347-
try await secondReleaseResult
347+
await secondReleaseResult
348348
#expect(await roomToReturn.releaseCallCount == 1)
349349
}
350350

@@ -371,7 +371,7 @@ struct DefaultRoomsTests {
371371
try #require(await rooms.testsOnly_hasRoomMapEntryWithID(roomID))
372372

373373
// When: `release(roomID:)` is called with this room ID
374-
_ = try await rooms.release(roomID: roomID)
374+
_ = await rooms.release(roomID: roomID)
375375

376376
// Then:
377377
// 1. first, the room is removed from the room map

Tests/AblyChatTests/IntegrationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ struct IntegrationTests {
281281
// MARK: - Release
282282

283283
// (1) Release the room
284-
try await rxClient.rooms.release(roomID: roomID)
284+
await rxClient.rooms.release(roomID: roomID)
285285

286286
// (2) Check that we received a RELEASED status change as a result of releasing the room
287287
_ = try #require(await rxRoomStatusSubscription.first { $0.current == .released })

0 commit comments

Comments
 (0)