Skip to content

Commit 22382ba

Browse files
authored
Revert behavior for non SnapShot scenario to throw an exception when initialization fails (#1884)
1 parent 45aa0d8 commit 22382ba

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Projects": [
3+
{
4+
"Name": "Amazon.Lambda.RuntimeSupport",
5+
"Type": "Patch",
6+
"ChangelogMessages": [
7+
"Revert behavior for non SnapShot scenario to throw an exception when initialization fails"
8+
]
9+
}
10+
]
11+
}

Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ internal async Task<bool> InitializeAsync()
219219
System.Environment.Exit(1); // This needs to be non-zero for Lambda Sandbox to know that Runtime client encountered an exception
220220
}
221221
#endif
222+
throw;
222223
}
223-
return false;
224224
}
225225

226226
internal async Task InvokeOnceAsync(CancellationToken cancellationToken = default)

Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/LambdaBootstrapTests.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,23 @@ public async Task NoInitializer()
8383
}
8484

8585
[Fact]
86-
public async Task InitializerHandlesExceptionsGracefully()
86+
public async Task InitializerHandlesExceptions()
8787
{
88+
bool exceptionThrown = false;
8889
using (var bootstrap = new LambdaBootstrap(_testFunction.BaseHandlerAsync, _testInitializer.InitializeThrowAsync))
8990
{
9091
bootstrap.Client = _testRuntimeApiClient;
91-
await bootstrap.RunAsync();
92+
try
93+
{
94+
await bootstrap.RunAsync();
95+
}
96+
catch
97+
{
98+
exceptionThrown = true;
99+
}
92100
}
93101

102+
Assert.True(exceptionThrown);
94103
Assert.True(_testRuntimeApiClient.ReportInitializationErrorAsyncExceptionCalled);
95104
Assert.True(_testInitializer.InitializerWasCalled);
96105
Assert.False(_testFunction.HandlerWasCalled);

0 commit comments

Comments
 (0)