Catch errors when storage is not sufficient

This commit is contained in:
Leon Böttger committed 2025-07-24 15:34:48 +02:00
1 parent 404e25d3bd
commit 2939990607
3 files changed
+27 -16

No files matched your search

+18 -8
View File
@@ -64,19 +64,23 @@ class InboundNearbyConnection: NearbyConnection {
try processConnectionResponseFrame(frame) try processConnectionResponseFrame(frame)
default: default:
do { var smsg: Securemessage_SecureMessage? = nil
let smsg = try Securemessage_SecureMessage(serializedBytes: frameData)
try decryptAndProcessReceivedSecureMessage(smsg)
} catch {
do {
smsg = try Securemessage_SecureMessage(serializedBytes: frameData)
} catch {
log("Error deserializing secure message (probably due to packet filter)") log("Error deserializing secure message (probably due to packet filter)")
lastError = NearbyError.packetFilterError lastError = NearbyError.packetFilterError
protocolError() protocolError()
} }
if let smsg = smsg {
try decryptAndProcessReceivedSecureMessage(smsg)
}
} }
} catch { } catch {
lastError = error lastError = error
log("Deserialization error: \(error) in state \(currentState).") log("Error receiving frame: \(error) in state \(currentState).")
protocolError() protocolError()
} }
} }
@@ -117,9 +121,15 @@ class InboundNearbyConnection: NearbyConnection {
guard currentOffset + Int64(frame.payloadChunk.body.count) <= fileInfo.meta.size else { throw NearbyError.protocolError("Transferred file size exceeds previously specified value") } guard currentOffset + Int64(frame.payloadChunk.body.count) <= fileInfo.meta.size else { throw NearbyError.protocolError("Transferred file size exceeds previously specified value") }
if frame.payloadChunk.body.count > 0 { if frame.payloadChunk.body.count > 0 {
fileInfo.fileHandle?.write(frame.payloadChunk.body) do {
transferredFiles[id]!.bytesTransferred += Int64(frame.payloadChunk.body.count) try fileInfo.fileHandle?.write(contentsOf: frame.payloadChunk.body)
fileInfo.progress?.completedUnitCount = transferredFiles[id]!.bytesTransferred transferredFiles[id]!.bytesTransferred += Int64(frame.payloadChunk.body.count)
fileInfo.progress?.completedUnitCount = transferredFiles[id]!.bytesTransferred
} catch {
log("Error occurred during writing file: \(error.localizedDescription)")
throw NearbyError.protocolError(error.localizedDescription)
}
} }
else if (frame.payloadChunk.flags & 1) == 1 { else if (frame.payloadChunk.flags & 1) == 1 {
try fileInfo.fileHandle?.close() try fileInfo.fileHandle?.close()
+4 -4
View File
@@ -827,8 +827,8 @@
MTL_FAST_MATH = YES; MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx; SDKROOT = macosx;
SHARED_BUILD = 48; SHARED_BUILD = 49;
SHARED_VERSION = 1.10; SHARED_VERSION = 1.10.1;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
}; };
@@ -886,8 +886,8 @@
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES; MTL_FAST_MATH = YES;
SDKROOT = macosx; SDKROOT = macosx;
SHARED_BUILD = 48; SHARED_BUILD = 49;
SHARED_VERSION = 1.10; SHARED_VERSION = 1.10.1;
SWIFT_COMPILATION_MODE = wholemodule; SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O"; SWIFT_OPTIMIZATION_LEVEL = "-O";
}; };
+5 -4
View File
@@ -465,14 +465,15 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
switch ne { switch ne {
case .inputOutput: case .inputOutput:
description = "I/O Error" description = "I/O Error"
case .protocolError: case .protocolError(errorMessage: let errorMessage):
description = NSLocalizedString("Error.Protocol", value: "Communication error", comment: "") + "(\(ne.localizedDescription))" log("Protocol error ")
description = NSLocalizedString("Error.Protocol", value: "Communication error", comment: "") + " (\(errorMessage))"
case .packetFilterError: case .packetFilterError:
openAlert(type: .NetworkFilter) openAlert(type: .NetworkFilter)
plusWindow?.close() plusWindow?.close()
return return
case .requiredFieldMissing: case .requiredFieldMissing(errorMessage: let errorMessage):
description = NSLocalizedString("Error.Protocol", value: "Communication error", comment: "") + "(\(ne.localizedDescription))" description = NSLocalizedString("Error.Protocol", value: "Communication error", comment: "") + "(\(errorMessage))"
case .ukey2: case .ukey2:
description = NSLocalizedString("Error.Crypto", value: "Encryption error", comment: "") + "(\(ne.localizedDescription))" description = NSLocalizedString("Error.Crypto", value: "Encryption error", comment: "") + "(\(ne.localizedDescription))"
case .canceled(reason: _): case .canceled(reason: _):