diff --git a/Sources/SecureXPC/SequentialResultProvider.swift b/Sources/SecureXPC/SequentialResultProvider.swift index f5a659f..e0d2948 100644 --- a/Sources/SecureXPC/SequentialResultProvider.swift +++ b/Sources/SecureXPC/SequentialResultProvider.swift @@ -239,8 +239,12 @@ public class SequentialResultProvider { do { try encodingWork(&response) if let deliveryHandler = deliveryHandler { - xpc_connection_send_message_with_reply(connection, response, nil) { _ in - deliveryHandler(.success(())) + xpc_connection_send_message_with_reply(connection, response, nil) { result in + if xpc_get_type(result) == XPC_TYPE_ERROR { + deliveryHandler(.failure(XPCError.fromXPCObject(result))) + } else { + deliveryHandler(.success(())) + } } } else { xpc_connection_send_message(connection, response) diff --git a/Tests/SecureXPCTests/Client & Server/Sequential Result Tests.swift b/Tests/SecureXPCTests/Client & Server/Sequential Result Tests.swift index 4232338..2e50dc8 100644 --- a/Tests/SecureXPCTests/Client & Server/Sequential Result Tests.swift +++ b/Tests/SecureXPCTests/Client & Server/Sequential Result Tests.swift @@ -313,7 +313,8 @@ class SequentialResultTests: XCTestCase { } } - let expectation = self.expectation(description: "The second sequence value won't be decodable") + let secondSequenceValueNotDecodableExpectation = self.expectation(description: "The second sequence value won't be decodable") + let thirdSequenceValueSentExpectation = self.expectation(description: "Attempted to send third sequence value") enum ExampleError: Error, Codable { case didNotWork } @@ -325,10 +326,19 @@ class SequentialResultTests: XCTestCase { do { try await provider.success(value: .noValue) try await provider.success(value: .alwaysFailedDecode(NotActuallyDecodable())) - try await provider.success(value: .noValue) } catch { XCTFail("Unexpected error: \(error)") } + do { + try await provider.success(value: .noValue) + XCTFail("Sending the third reply should fail with an XPCError.connectionInterrupted error") + } + catch XPCError.connectionInterrupted { + // Expected error + } catch { + XCTFail("Unexpected error: \(error)") + } + thirdSequenceValueSentExpectation.fulfill() } let sequence = client.send(to: route) @@ -340,10 +350,10 @@ class SequentialResultTests: XCTestCase { _ = try await iterator.next() } catch { if case XPCError.decodingError(_) = error { - expectation.fulfill() + secondSequenceValueNotDecodableExpectation.fulfill() } } - + await self.waitForExpectations(timeout: 1) }