fix(mac): avoid crash decoding gateway frames

This commit is contained in:
Peter Steinberger
2025-12-09 17:36:16 +00:00
parent 1f19ca1665
commit fcc8d59588
3 changed files with 38 additions and 2 deletions

View File

@@ -500,7 +500,12 @@ public enum GatewayFrame: Codable {
}
private static func decodePayload<T: Decodable>(_ type: T.Type, from raw: [String: AnyCodable]) throws -> T {
let data = try JSONSerialization.data(withJSONObject: raw)
// Re-encode the already-decoded map using `JSONEncoder` instead of
// `JSONSerialization` because `AnyCodable` values are not bridged to
// Objective-C types and `JSONSerialization` throws an ObjC exception,
// crashing the app (seen on macOS 26.1). `JSONEncoder` understands
// `Encodable` values and stays in Swift land.
let data = try JSONEncoder().encode(raw)
let decoder = JSONDecoder()
return try decoder.decode(T.self, from: data)
}