diff --git a/Sources/AWSLambdaRuntime/LambdaRuntimeClient+ChannelHandler.swift b/Sources/AWSLambdaRuntime/LambdaRuntimeClient+ChannelHandler.swift index 2b66ee87..ed0a8733 100644 --- a/Sources/AWSLambdaRuntime/LambdaRuntimeClient+ChannelHandler.swift +++ b/Sources/AWSLambdaRuntime/LambdaRuntimeClient+ChannelHandler.swift @@ -334,7 +334,7 @@ internal final class LambdaChannelHandler GetInvocationResult { + .success((self.requestId, self.event)) + } + + func processResponse(requestId: String, response: String?) -> Result { + Issue.record("should not process response, expecting error report") + return .failure(.internalServerError) + } + + func processError(requestId: String, error: ErrorResponse) -> Result { + #expect(self.requestId == requestId) + #expect( + error.errorType == self.expectedErrorType, + "Expected errorType '\(self.expectedErrorType)' but got '\(error.errorType)'" + ) + return .success(()) + } + + func processInitError(error: ErrorResponse) -> Result { + Issue.record("should not report init error") + return .failure(.internalServerError) + } + } + + // Test with MyCustomError + try await withMockServer(behaviour: ErrorReportingBehavior(expectedErrorType: "MyCustomError")) { port in + let configuration = LambdaRuntimeClient.Configuration(ip: "127.0.0.1", port: port) + + try await LambdaRuntimeClient.withRuntimeClient( + configuration: configuration, + eventLoop: NIOSingletons.posixEventLoopGroup.next(), + logger: self.logger + ) { runtimeClient in + let (_, writer) = try await runtimeClient.nextInvocation() + let error = MyCustomError(message: "Something went wrong") + try await writer.reportError(error) + } + } + + // Test with MyEnumError + try await withMockServer(behaviour: ErrorReportingBehavior(expectedErrorType: "MyEnumError")) { port in + let configuration = LambdaRuntimeClient.Configuration(ip: "127.0.0.1", port: port) + + try await LambdaRuntimeClient.withRuntimeClient( + configuration: configuration, + eventLoop: NIOSingletons.posixEventLoopGroup.next(), + logger: self.logger + ) { runtimeClient in + let (_, writer) = try await runtimeClient.nextInvocation() + let error = MyEnumError.anotherCase("test") + try await writer.reportError(error) + } + } + } }