From 2c2ccdf7518f3a8998bbb6a2222d66e25a34900e Mon Sep 17 00:00:00 2001 From: Ben Rosen Date: Tue, 14 Oct 2025 13:37:52 -0500 Subject: [PATCH 1/6] make it so errors thrown in the lambda handler will output the type of the error in the response instead of a constant FunctionError --- .../AWSLambdaRuntime/LambdaRuntimeClient+ChannelHandler.swift | 2 +- Sources/AWSLambdaRuntime/Utils.swift | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) 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 Date: Tue, 14 Oct 2025 15:01:53 -0500 Subject: [PATCH 2/6] add in a unit test to ensure that this behavior does not regress --- .../LambdaRuntimeClientTests.swift | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift b/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift index a5b22471..8bf85d87 100644 --- a/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift +++ b/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift @@ -330,4 +330,78 @@ struct LambdaRuntimeClientTests { } } } + + @Test( + "reportError() sends the correct errorType for different Error types", + ) + @available(LambdaSwift 2.0, *) + func testReportErrorReturnsProperErrorType() async throws { + // Custom error types for testing + struct MyCustomError: Error { + let message: String + } + + enum MyEnumError: Error { + case anotherCase(String) + } + + struct ErrorReportingBehavior: LambdaServerBehavior { + let requestId = UUID().uuidString + let event = "error-testing" + let expectedErrorType: String + + func getInvocation() -> 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) + } + } + } } From 6759abd5bccb7984202c149cf6a5e3157caab133 Mon Sep 17 00:00:00 2001 From: Ben Rosen Date: Tue, 14 Oct 2025 16:17:25 -0500 Subject: [PATCH 3/6] Remove a stray comma in @test which is causing compilation issues --- Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift b/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift index 8bf85d87..2ba38496 100644 --- a/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift +++ b/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift @@ -332,7 +332,7 @@ struct LambdaRuntimeClientTests { } @Test( - "reportError() sends the correct errorType for different Error types", + "reportError() sends the correct errorType for different Error types" ) @available(LambdaSwift 2.0, *) func testReportErrorReturnsProperErrorType() async throws { From 9abd180489f851113e46c4415653a46fe92a2345 Mon Sep 17 00:00:00 2001 From: Ben Rosen Date: Tue, 14 Oct 2025 16:23:46 -0500 Subject: [PATCH 4/6] I believe I forgot a .finish call which is needed for proper cleanup and was causing failed tests --- Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift b/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift index 2ba38496..0f336756 100644 --- a/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift +++ b/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift @@ -386,6 +386,7 @@ struct LambdaRuntimeClientTests { let (_, writer) = try await runtimeClient.nextInvocation() let error = MyCustomError(message: "Something went wrong") try await writer.reportError(error) + try await writer.finish() } } @@ -401,6 +402,7 @@ struct LambdaRuntimeClientTests { let (_, writer) = try await runtimeClient.nextInvocation() let error = MyEnumError.anotherCase("test") try await writer.reportError(error) + try await writer.finish() } } } From 11b551c6f428653863d0ce323dd2a19f19d12e6c Mon Sep 17 00:00:00 2001 From: Ben Rosen Date: Tue, 14 Oct 2025 16:38:26 -0500 Subject: [PATCH 5/6] Revert "I believe I forgot a .finish call which is needed for proper cleanup and was causing failed tests" This reverts commit 9abd180489f851113e46c4415653a46fe92a2345. --- Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift b/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift index 0f336756..2ba38496 100644 --- a/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift +++ b/Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift @@ -386,7 +386,6 @@ struct LambdaRuntimeClientTests { let (_, writer) = try await runtimeClient.nextInvocation() let error = MyCustomError(message: "Something went wrong") try await writer.reportError(error) - try await writer.finish() } } @@ -402,7 +401,6 @@ struct LambdaRuntimeClientTests { let (_, writer) = try await runtimeClient.nextInvocation() let error = MyEnumError.anotherCase("test") try await writer.reportError(error) - try await writer.finish() } } } From 715e562e082ee7a5f06fe21fa8a763a4cdc0c6d0 Mon Sep 17 00:00:00 2001 From: Ben Rosen Date: Tue, 14 Oct 2025 17:13:35 -0500 Subject: [PATCH 6/6] Trigger Build