Skip to content

Commit 5e125d8

Browse files
fix: remove force-unwrap on session dictionary in DefaultNetworkService (#1787)
- Instead of using force-unwrap to append to a list-valued dictionary entry that should always exist, assign the value with a default fallback and append to the (non-optional) result.
1 parent 0e3651b commit 5e125d8

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

Sources/Services/Network/Server/DefaultNetworkService.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ public actor DefaultNetworkService: NetworkService {
9595
}
9696
macAddresses[index] = macAddress
9797

98-
if allocationsBySession[session] == nil {
99-
allocationsBySession[session] = []
98+
let isNewSession = allocationsBySession[session] == nil
99+
allocationsBySession[session, default: []].append((hostname: hostname, index: index))
100+
if isNewSession {
100101
await session.onDisconnect { [weak self] in
101102
await self?.releaseSession(session)
102103
}
103104
}
104-
allocationsBySession[session]!.append((hostname: hostname, index: index))
105105

106106
return (attachment: attachment, additionalData: additionalData)
107107
}

0 commit comments

Comments
 (0)