From e828edd6ae226d702bbabce24c9940e55009fad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6ttger?= Date: Sun, 8 Mar 2026 15:44:25 +0100 Subject: [PATCH] Better error handling --- NearbyShare/Connection/NearbyConnection.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/NearbyShare/Connection/NearbyConnection.swift b/NearbyShare/Connection/NearbyConnection.swift index 9edf192..f947bb7 100644 --- a/NearbyShare/Connection/NearbyConnection.swift +++ b/NearbyShare/Connection/NearbyConnection.swift @@ -189,7 +189,14 @@ class NearbyConnection { } guard let content = content else { log("[NearbyConnection \(self.id)] Received nil content during receiveFrameAsync(). IsComplete: \(isComplete)") - assertionFailure() + self.lastError = NearbyError.protocolError("Received empty frame header") + self.protocolError() + return + } + guard content.count == 4 else { + log("[NearbyConnection \(self.id)] Received invalid frame header size \(content.count), expected 4") + self.lastError = NearbyError.protocolError("Unexpected frame header length") + self.protocolError() return } let frameLength = UInt32(content[0]) << 24 | UInt32(content[1]) << 16 | UInt32(content[2]) << 8 | UInt32(content[3])