Skip to content

Commit

Permalink
Revert behavor for non SnapShot scenario to throw an exception when i…
Browse files Browse the repository at this point in the history
…nitialize fails
  • Loading branch information
normj committed Nov 25, 2024
1 parent 8f8e5a3 commit adac646
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
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 behavor for non SnapShot scenario to throw an exception when initialize 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

0 comments on commit adac646

Please sign in to comment.