Skip to content

Commit ae4acbf

Browse files
Don't fatalError on unknown channel state
I think it's very unlikely that we're ever going to add a new channel state without also doing a major release of the Chat SDK, but let's be graceful about it anyway.
1 parent d1555e1 commit ae4acbf

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/AblyChat/RoomLifecycleManager.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal final class DefaultRoomLifecycleManagerFactory: RoomLifecycleManagerFac
5454
}
5555

5656
private extension RoomStatus {
57-
init(channelState: ARTRealtimeChannelState) {
57+
init?(channelState: ARTRealtimeChannelState) {
5858
switch channelState {
5959
case .initialized:
6060
self = .initialized
@@ -71,7 +71,7 @@ private extension RoomStatus {
7171
case .failed:
7272
self = .failed
7373
@unknown default:
74-
fatalError("Unknown channel state \(channelState)")
74+
return nil
7575
}
7676
}
7777
}
@@ -199,8 +199,12 @@ internal class DefaultRoomLifecycleManager: RoomLifecycleManager {
199199

200200
// CHA-RL11b
201201
if event.event != .update, !hasOperationInProgress {
202-
// CHA-RL11c
203-
changeStatus(to: .init(channelState: event.current), error: event.reason)
202+
if let roomStatus = RoomStatus(channelState: event.current) {
203+
// CHA-RL11c
204+
changeStatus(to: roomStatus, error: event.reason)
205+
} else {
206+
logger.log(message: "Got unknown channel state \(event.current)", level: .info)
207+
}
204208
}
205209

206210
switch event.event {

0 commit comments

Comments
 (0)