generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 33
Closed
Labels
area/loggingCore logging utilityCore logging utilitybugUnexpected, reproducible and unintended software behaviourUnexpected, reproducible and unintended software behaviour
Description
Expected Behaviour
LoggingLambdaContext.Extract should check if the LambdaContext is not null regardless of if its position in the parameters list, and return false (the same way it does if other checks fail).
Current Behaviour
Currently, LoggingLambdaContext.Extract will throw an exception if the ILambdaContext is null and not the first parameter in a lambda method.
Code snippet
// add this unit test to https://github.com/aws-powertools/powertools-lambda-dotnet/blob/develop/libraries/tests/AWS.Lambda.Powertools.Logging.Tests/Context/LambdaContextTest.cs and you will see the exception:
[Fact]
public void Extract_Extract_When_LambdaContext_Is_Null_But_Not_First_Parameter_Returns_False()
{
// Arrange
ILambdaContext lambdaContext = null;
var args = Substitute.For<AspectEventArgs>();
var method = Substitute.For<MethodInfo>();
var parameter1 = Substitute.For<ParameterInfo>();
var parameter2 = Substitute.For<ParameterInfo>();
// Setup parameters
parameter1.ParameterType.Returns(typeof(string));
parameter2.ParameterType.Returns(typeof(ILambdaContext));
// Setup method
method.GetParameters().Returns(new[] { parameter1, parameter2 });
// Setup args
args.Method = method;
args.Args = new object[] { "requestContext", lambdaContext };
// Act && Assert
LoggingLambdaContext.Clear();
Assert.Null(LoggingLambdaContext.Instance);
Assert.False(LoggingLambdaContext.Extract(args)); // exception will be thrown here, instead of returning false
}Possible Solution
Steps to Reproduce
As shown in the code above.
Powertools for AWS Lambda (.NET) version
latest
AWS Lambda function runtime
dotnet8
Debugging logs
Metadata
Metadata
Assignees
Labels
area/loggingCore logging utilityCore logging utilitybugUnexpected, reproducible and unintended software behaviourUnexpected, reproducible and unintended software behaviour
Type
Projects
Status
✅ Done