Skip to content

Commit 7f55253

Browse files
authored
Removing warnings from Amazon.Lambda.RuntimeSupport (#2125)
1 parent 9f86dbd commit 7f55253

16 files changed

+207
-89
lines changed

Libraries/src/Amazon.Lambda.RuntimeSupport/Amazon.Lambda.RuntimeSupport.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<Import Project="..\..\..\buildtools\common.props" />
44

@@ -13,7 +13,9 @@
1313
<PackageReadmeFile>README.md</PackageReadmeFile>
1414
<GenerateAssemblyVersionAttribute>true</GenerateAssemblyVersionAttribute>
1515
<GenerateAssemblyFileVersionAttribute>true</GenerateAssemblyFileVersionAttribute>
16-
<LangVersion>9.0</LangVersion>
16+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
17+
<NoWarn>NU5048;NU1903;NU1902</NoWarn>
18+
<LangVersion>9.0</LangVersion>
1719
</PropertyGroup>
1820

1921
<PropertyGroup Condition=" '$(ExecutableOutputType)'=='true' ">
@@ -22,7 +24,6 @@
2224
</PropertyGroup>
2325

2426
<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0' or '$(TargetFramework)' == 'net9.0' or '$(TargetFramework)' == 'net10.0'">
25-
<WarningsAsErrors>IL2026,IL2067,IL2075</WarningsAsErrors>
2627
<IsTrimmable>true</IsTrimmable>
2728
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
2829
</PropertyGroup>

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
@@ -29,8 +29,11 @@ public class HandlerWrapper : IDisposable
2929
private static readonly InvocationResponse EmptyInvocationResponse =
3030
new InvocationResponse(new MemoryStream(0), false);
3131

32-
private MemoryStream OutputStream = new MemoryStream();
32+
private readonly MemoryStream OutputStream = new MemoryStream();
3333

34+
/// <summary>
35+
/// The handler that will be called for each event.
36+
/// </summary>
3437
public LambdaBootstrapHandler Handler { get; private set; }
3538

3639
private HandlerWrapper(LambdaBootstrapHandler handler)
@@ -163,7 +166,7 @@ public static HandlerWrapper GetHandlerWrapper<TInput>(Func<TInput, ILambdaConte
163166
/// <summary>
164167
/// Get a HandlerWrapper that will call the given method on function invocation.
165168
/// Note that you may have to cast your handler to its specific type to help the compiler.
166-
/// Example handler signature: Task&ltStream&gt Handler()
169+
/// Example handler signature: Task&lt;Stream&gt; Handler()
167170
/// </summary>
168171
/// <param name="handler">Func called for each invocation of the Lambda function.</param>
169172
/// <returns>A HandlerWrapper</returns>
@@ -178,7 +181,7 @@ public static HandlerWrapper GetHandlerWrapper(Func<Task<Stream>> handler)
178181
/// <summary>
179182
/// Get a HandlerWrapper that will call the given method on function invocation.
180183
/// Note that you may have to cast your handler to its specific type to help the compiler.
181-
/// Example handler signature: Task&ltStream&gt Handler(Stream)
184+
/// Example handler signature: Task&lt;Stream&gt; Handler(Stream)
182185
/// </summary>
183186
/// <param name="handler">Func called for each invocation of the Lambda function.</param>
184187
/// <returns>A HandlerWrapper</returns>
@@ -193,7 +196,7 @@ public static HandlerWrapper GetHandlerWrapper(Func<Stream, Task<Stream>> handle
193196
/// <summary>
194197
/// Get a HandlerWrapper that will call the given method on function invocation.
195198
/// Note that you may have to cast your handler to its specific type to help the compiler.
196-
/// Example handler signature: Task&ltStream&gt Handler(PocoIn)
199+
/// Example handler signature: Task&lt;Stream&gt; Handler(PocoIn)
197200
/// </summary>
198201
/// <param name="handler">Func called for each invocation of the Lambda function.</param>
199202
/// <param name="serializer">ILambdaSerializer to use when calling the handler</param>
@@ -210,7 +213,7 @@ public static HandlerWrapper GetHandlerWrapper<TInput>(Func<TInput, Task<Stream>
210213
/// <summary>
211214
/// Get a HandlerWrapper that will call the given method on function invocation.
212215
/// Note that you may have to cast your handler to its specific type to help the compiler.
213-
/// Example handler signature: Task&ltStream&gt Handler(ILambdaContext)
216+
/// Example handler signature: Task&lt;Stream&gt; Handler(ILambdaContext)
214217
/// </summary>
215218
/// <param name="handler">Func called for each invocation of the Lambda function.</param>
216219
/// <returns>A HandlerWrapper</returns>
@@ -225,7 +228,7 @@ public static HandlerWrapper GetHandlerWrapper(Func<ILambdaContext, Task<Stream>
225228
/// <summary>
226229
/// Get a HandlerWrapper that will call the given method on function invocation.
227230
/// Note that you may have to cast your handler to its specific type to help the compiler.
228-
/// Example handler signature: Task&ltStream&gt Handler(Stream, ILambdaContext)
231+
/// Example handler signature: Task&lt;Stream&gt; Handler(Stream, ILambdaContext)
229232
/// </summary>
230233
/// <param name="handler">Func called for each invocation of the Lambda function.</param>
231234
/// <returns>A HandlerWrapper</returns>
@@ -240,7 +243,7 @@ public static HandlerWrapper GetHandlerWrapper(Func<Stream, ILambdaContext, Task
240243
/// <summary>
241244
/// Get a HandlerWrapper that will call the given method on function invocation.
242245
/// Note that you may have to cast your handler to its specific type to help the compiler.
243-
/// Example handler signature: Task&ltStream&gt Handler(PocoIn, ILambdaContext)
246+
/// Example handler signature: Task&lt;Stream&gt; Handler(PocoIn, ILambdaContext)
244247
/// </summary>
245248
/// <param name="handler">Func called for each invocation of the Lambda function.</param>
246249
/// <param name="serializer">ILambdaSerializer to use when calling the handler</param>
@@ -257,7 +260,7 @@ public static HandlerWrapper GetHandlerWrapper<TInput>(Func<TInput, ILambdaConte
257260
/// <summary>
258261
/// Get a HandlerWrapper that will call the given method on function invocation.
259262
/// Note that you may have to cast your handler to its specific type to help the compiler.
260-
/// Example handler signature: Task&ltPocoOut&gt Handler()
263+
/// Example handler signature: Task&lt;PocoOut&gt; Handler()
261264
/// </summary>
262265
/// <param name="handler">Func called for each invocation of the Lambda function.</param>
263266
/// <param name="serializer">ILambdaSerializer to use when calling the handler</param>
@@ -279,7 +282,7 @@ public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<Task<TOutput>> hand
279282
/// <summary>
280283
/// Get a HandlerWrapper that will call the given method on function invocation.
281284
/// Note that you may have to cast your handler to its specific type to help the compiler.
282-
/// Example handler signature: Task&ltPocoOut&gt Handler(Stream)
285+
/// Example handler signature: Task&lt;PocoOut&gt; Handler(Stream)
283286
/// </summary>
284287
/// <param name="handler">Func called for each invocation of the Lambda function.</param>
285288
/// <param name="serializer">ILambdaSerializer to use when calling the handler</param>
@@ -301,7 +304,7 @@ public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<Stream, Task<TOutpu
301304
/// <summary>
302305
/// Get a HandlerWrapper that will call the given method on function invocation.
303306
/// Note that you may have to cast your handler to its specific type to help the compiler.
304-
/// Example handler signature: Task&ltPocoOut&gt Handler(PocoIn)
307+
/// Example handler signature: Task&lt;PocoOut&gt; Handler(PocoIn)
305308
/// </summary>
306309
/// <param name="handler">Func called for each invocation of the Lambda function.</param>
307310
/// <param name="serializer">ILambdaSerializer to use when calling the handler</param>
@@ -324,7 +327,7 @@ public static HandlerWrapper GetHandlerWrapper<TInput, TOutput>(Func<TInput, Tas
324327
/// <summary>
325328
/// Get a HandlerWrapper that will call the given method on function invocation.
326329
/// Note that you may have to cast your handler to its specific type to help the compiler.
327-
/// Example handler signature: Task&ltPocoOut&gt Handler(ILambdaContext)
330+
/// Example handler signature: Task&lt;PocoOut&gt; Handler(ILambdaContext)
328331
/// </summary>
329332
/// <param name="handler">Func called for each invocation of the Lambda function.</param>
330333
/// <param name="serializer">ILambdaSerializer to use when calling the handler</param>
@@ -346,7 +349,7 @@ public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<ILambdaContext, Tas
346349
/// <summary>
347350
/// Get a HandlerWrapper that will call the given method on function invocation.
348351
/// Note that you may have to cast your handler to its specific type to help the compiler.
349-
/// Example handler signature: Task&ltPocoOut&gt Handler(Stream, ILambdaContext)
352+
/// Example handler signature: Task&lt;PocoOut&gt; Handler(Stream, ILambdaContext)
350353
/// </summary>
351354
/// <param name="handler">Func called for each invocation of the Lambda function.</param>
352355
/// <param name="serializer">ILambdaSerializer to use when calling the handler</param>
@@ -368,7 +371,7 @@ public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<Stream, ILambdaCont
368371
/// <summary>
369372
/// Get a HandlerWrapper that will call the given method on function invocation.
370373
/// Note that you may have to cast your handler to its specific type to help the compiler.
371-
/// Example handler signature: Task&ltPocoOut&gt Handler(PocoIn, ILambdaContext)
374+
/// Example handler signature: Task&lt;PocoOut&gt; Handler(PocoIn, ILambdaContext)
372375
/// </summary>
373376
/// <param name="handler">Func called for each invocation of the Lambda function.</param>
374377
/// <param name="serializer">ILambdaSerializer to use when calling the handler</param>
@@ -719,6 +722,9 @@ public static HandlerWrapper GetHandlerWrapper<TInput, TOutput>(Func<TInput, ILa
719722
#region IDisposable Support
720723
private bool disposedValue = false; // To detect redundant calls
721724

725+
/// <summary>
726+
/// Dispose the HandlerWrapper
727+
/// </summary>
722728
protected virtual void Dispose(bool disposing)
723729
{
724730
if (!disposedValue)
@@ -732,6 +738,9 @@ protected virtual void Dispose(bool disposing)
732738
}
733739
}
734740

741+
/// <summary>
742+
/// Dispose the HandlerWrapper
743+
/// </summary>
735744
public void Dispose()
736745
{
737746
Dispose(true);

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public InvokeDelegateBuilder(InternalLogger logger, HandlerInfo handler, MethodI
4949
/// <summary>
5050
/// Constructs the invoke delegate using Expressions
5151
///
52-
/// Serialize & Deserialize calls are only made when a serializer is provided.
52+
/// Serialize and Deserialize calls are only made when a serializer is provided.
5353
/// Context is only passed when customer method has context parameter.
5454
/// Lambda return type can be void.
5555
///
@@ -62,7 +62,8 @@ public InvokeDelegateBuilder(InternalLogger logger, HandlerInfo handler, MethodI
6262
///
6363
/// </summary>
6464
/// <param name="customerObject">Wrapped customer object.</param>
65-
/// <param name="customerSerializerInstance">Instance of lambda input & output serializer.</param>
65+
/// <param name="customerSerializerInstance">Instance of lambda input &amp; output serializer.</param>
66+
/// <param name="isPreJit">If true forces more .NET code to get loaded during startup for jitting.</param>
6667
/// <returns>Action delegate pointing to customer's handler.</returns>
6768
#if NET8_0_OR_GREATER
6869
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("ConstructInvokeDelegate does not support trimming and is meant to be used in class library based Lambda functions.")]
@@ -73,54 +74,54 @@ public Action<Stream, ILambdaContext, Stream> ConstructInvokeDelegate(object cus
7374
var outStreamParameter = Expression.Parameter(Types.StreamType, "outStream");
7475
var contextParameter = Expression.Parameter(typeof(ILambdaContext), "context");
7576

76-
_logger.LogDebug($"UCL : Constructing input expression");
77+
_logger.LogDebug("UCL : Constructing input expression");
7778
var inputExpression = BuildInputExpressionOrNull(customerSerializerInstance, inStreamParameter, out var iLambdaContextType);
7879
if (isPreJit)
7980
{
8081
_logger.LogInformation("PreJit: inputExpression");
8182
UserCodeInit.InitDeserializationAssembly(inputExpression, inStreamParameter);
8283
}
8384

84-
_logger.LogDebug($"UCL : Constructing context expression");
85+
_logger.LogDebug("UCL : Constructing context expression");
8586
var contextExpression = BuildContextExpressionOrNull(iLambdaContextType, contextParameter);
8687

87-
_logger.LogDebug($"UCL : Constructing handler expression");
88+
_logger.LogDebug("UCL : Constructing handler expression");
8889
var handlerExpression = CreateHandlerCallExpression(customerObject, inputExpression, contextExpression);
8990

90-
_logger.LogDebug($"UCL : Constructing output expression");
91+
_logger.LogDebug("UCL : Constructing output expression");
9192
var outputExpression = CreateOutputExpression(customerSerializerInstance, outStreamParameter, handlerExpression);
9293
if (isPreJit)
9394
{
9495
_logger.LogInformation("PreJit: outputExpression");
9596
UserCodeInit.InitSerializationAssembly(outputExpression, outStreamParameter, CustomerOutputType);
9697
}
9798

98-
_logger.LogDebug($"UCL : Constructing final expression");
99+
_logger.LogDebug("UCL : Constructing final expression");
99100

100101
var finalExpression = Expression.Lambda<Action<Stream, ILambdaContext, Stream>>(outputExpression, inStreamParameter, contextParameter, outStreamParameter);
101102
#if DEBUG
102103
var finalExpressionDebugView = typeof(Expression)
103104
.GetTypeInfo()
104105
.GetProperty("DebugView", BindingFlags.Instance | BindingFlags.NonPublic)
105106
.GetValue(finalExpression);
106-
_logger.LogDebug($"UCL : Constructed final expression:\n'{finalExpressionDebugView}'");
107+
_logger.LogDebug("UCL : Constructed final expression:\n'{finalExpressionDebugView}'");
107108
#endif
108109

109-
_logger.LogDebug($"UCL : Compiling final expression");
110+
_logger.LogDebug("UCL : Compiling final expression");
110111
return finalExpression.Compile();
111112
}
112113

113114
/// <summary>
114115
/// Creates an expression to convert incoming Stream to the customer method inputs.
115116
/// If customer method takes no inputs or only takes ILambdaContext, return null.
116117
/// </summary>
117-
/// <param name="customerSerializerInstance">Instance of lambda input & output serializer.</param>
118+
/// <param name="customerSerializerInstance">Instance of lambda input and output serializer.</param>
118119
/// <param name="inStreamParameter">Input stream parameter.</param>
119120
/// <param name="iLambdaContextType">Type of context passed for the invocation.</param>
120121
/// <returns>Expression that deserializes incoming stream to the customer method inputs or null if customer method takes no input.</returns>
121122
/// <exception cref="LambdaValidationException">Thrown when customer method inputs don't meet lambda requirements.</exception>
122123
#if NET8_0_OR_GREATER
123-
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("BuildInputExpressionOrNull does not support trimming and is meant to be used in class library based Lambda functions.")]
124+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("BuildInputExpressionOrNull does not support trimming and is meant to be used in class library based Lambda functions.")]
124125
#endif
125126
private Expression BuildInputExpressionOrNull(object customerSerializerInstance, Expression inStreamParameter, out Type iLambdaContextType)
126127
{
@@ -171,7 +172,7 @@ private Expression BuildInputExpressionOrNull(object customerSerializerInstance,
171172

172173
if (iLambdaContextType != null)
173174
{
174-
_logger.LogDebug($"UCL : Validating iLambdaContextType");
175+
_logger.LogDebug("UCL : Validating iLambdaContextType");
175176
UserCodeValidator.ValidateILambdaContextType(iLambdaContextType);
176177
}
177178

@@ -257,7 +258,7 @@ private Expression CreateHandlerCallExpression(object customerObject, Expression
257258
/// is just the handler call expression. Otherwise, the final expression is the
258259
/// serialization expression operating on the handler call expression.
259260
/// </summary>
260-
/// <param name="customerSerializerInstance">Instance of lambda input & output serializer.</param>
261+
/// <param name="customerSerializerInstance">Instance of lambda input and output serializer.</param>
261262
/// <param name="outStreamParameter">Expression that defines customer output.</param>
262263
/// <param name="handlerCallExpression">Expression that defines customer handler call.</param>
263264
/// <returns>Expression that serializes customer method output to outgoing stream.</returns>
@@ -313,12 +314,12 @@ private static Type GetTaskTSubclassOrNull(Type type)
313314
/// <summary>
314315
/// Generates an expression to serialize customer method result into the output stream
315316
/// </summary>
316-
/// <param name="customerSerializerInstance">Instance of lambda input & output serializer.</param>
317+
/// <param name="customerSerializerInstance">Instance of lambda input and output serializer.</param>
317318
/// <param name="dataType">Customer input type.</param>
318319
/// <param name="customerObject">Expression that define customer object.</param>
319320
/// <param name="outStreamParameter">Expression that defines customer output.</param>
320321
/// <returns>Expression that serializes returned object to output stream.</returns>
321-
/// <exception cref="LambdaValidationException">Thrown when customer input is serializable & serializer instance is null.</exception>
322+
/// <exception cref="LambdaValidationException">Thrown when customer input is serializable &amp; serializer instance is null.</exception>
322323
#if NET8_0_OR_GREATER
323324
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("CreateSerializeExpression does not support trimming and is meant to be used in class library based Lambda functions.")]
324325
#endif
@@ -371,7 +372,7 @@ private Expression CreateSerializeExpression(object customerSerializerInstance,
371372
/// <summary>
372373
/// Generates an expression to deserialize incoming data to customer method input
373374
/// </summary>
374-
/// <param name="customerSerializerInstance">Instance of lambda input & output serializer.</param>
375+
/// <param name="customerSerializerInstance">Instance of lambda input and output serializer.</param>
375376
/// <param name="dataType">Customer input type.</param>
376377
/// <param name="inStream">Input expression that defines customer input.</param>
377378
/// <returns>Expression that deserializes incoming data to customer method input.</returns>
@@ -411,4 +412,4 @@ private Expression CreateDeserializeExpression(object customerSerializerInstance
411412
return deserializeCall;
412413
}
413414
}
414-
}
415+
}

0 commit comments

Comments
 (0)