From 22382ba18e78a8bc5bb6f60e9bcfd7f22e218cfa Mon Sep 17 00:00:00 2001 From: Norm Johanson Date: Tue, 26 Nov 2024 11:28:30 -0800 Subject: [PATCH] Revert behavior for non SnapShot scenario to throw an exception when initialization fails (#1884) --- .../cd8cd757-830a-4abd-b01f-92176e837b07.json | 11 +++++++++++ .../Bootstrap/LambdaBootstrap.cs | 2 +- .../LambdaBootstrapTests.cs | 13 +++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 .autover/changes/cd8cd757-830a-4abd-b01f-92176e837b07.json diff --git a/.autover/changes/cd8cd757-830a-4abd-b01f-92176e837b07.json b/.autover/changes/cd8cd757-830a-4abd-b01f-92176e837b07.json new file mode 100644 index 000000000..126712648 --- /dev/null +++ b/.autover/changes/cd8cd757-830a-4abd-b01f-92176e837b07.json @@ -0,0 +1,11 @@ +{ + "Projects": [ + { + "Name": "Amazon.Lambda.RuntimeSupport", + "Type": "Patch", + "ChangelogMessages": [ + "Revert behavior for non SnapShot scenario to throw an exception when initialization fails" + ] + } + ] +} \ No newline at end of file diff --git a/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs b/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs index fa7996a84..e0ac20907 100644 --- a/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs +++ b/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs @@ -219,8 +219,8 @@ internal async Task InitializeAsync() System.Environment.Exit(1); // This needs to be non-zero for Lambda Sandbox to know that Runtime client encountered an exception } #endif + throw; } - return false; } internal async Task InvokeOnceAsync(CancellationToken cancellationToken = default) diff --git a/Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/LambdaBootstrapTests.cs b/Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/LambdaBootstrapTests.cs index 44f20aa7e..cafd83fe4 100644 --- a/Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/LambdaBootstrapTests.cs +++ b/Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/LambdaBootstrapTests.cs @@ -83,14 +83,23 @@ public async Task NoInitializer() } [Fact] - public async Task InitializerHandlesExceptionsGracefully() + public async Task InitializerHandlesExceptions() { + bool exceptionThrown = false; using (var bootstrap = new LambdaBootstrap(_testFunction.BaseHandlerAsync, _testInitializer.InitializeThrowAsync)) { bootstrap.Client = _testRuntimeApiClient; - await bootstrap.RunAsync(); + try + { + await bootstrap.RunAsync(); + } + catch + { + exceptionThrown = true; + } } + Assert.True(exceptionThrown); Assert.True(_testRuntimeApiClient.ReportInitializationErrorAsyncExceptionCalled); Assert.True(_testInitializer.InitializerWasCalled); Assert.False(_testFunction.HandlerWasCalled);