Skip to content

Commit 41e080a

Browse files
committed
fix: fail if encoding fails instead of silently omitting field
1 parent c15a057 commit 41e080a

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

ios/RNIterableAPI/Serialization.swift

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,21 +285,27 @@ extension InboxImpressionTracker.RowInfo {
285285
}
286286

287287
extension IterableEmbeddedMessage {
288-
func toDict() -> [AnyHashable: Any] {
288+
func toDict() -> [AnyHashable: Any]? {
289289
var dict = [AnyHashable: Any]()
290290

291-
// Serialize metadata (which is Codable)
292-
if let metadataDict = SerializationUtil.encodableToDictionary(encodable: metadata) {
293-
dict["metadata"] = metadataDict
291+
// CRITICAL: Metadata is required - fail if missing
292+
guard let metadataDict = SerializationUtil.encodableToDictionary(encodable: metadata) else {
293+
ITBError("Failed to serialize embedded message metadata. Dropping invalid message.")
294+
return nil
294295
}
295-
296-
// Serialize elements if present (which is Codable)
297-
if let elements = elements,
298-
let elementsDict = SerializationUtil.encodableToDictionary(encodable: elements) {
299-
dict["elements"] = elementsDict
296+
dict["metadata"] = metadataDict
297+
298+
// IMPORTANT: Elements are optional, but if present and fail to serialize, that's bad
299+
if let elements = elements {
300+
if let elementsDict = SerializationUtil.encodableToDictionary(encodable: elements) {
301+
dict["elements"] = elementsDict
302+
} else {
303+
ITBError("Failed to serialize embedded message elements. Message will not be displayable.")
304+
return nil
305+
}
300306
}
301307

302-
// Add payload directly
308+
// Payload doesn't need serialization - it's already a dictionary
303309
if let payload = payload {
304310
dict["payload"] = payload
305311
}

0 commit comments

Comments
 (0)