Skip to content

Revert behavior for non SnapShot scenario to throw an exception when initialize fails #1884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .autover/changes/cd8cd757-830a-4abd-b01f-92176e837b07.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ internal async Task<bool> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading