Add AWSLambda0145 diagnostic for unregistered durable envelope types#2464
Draft
GarrettBeatty wants to merge 1 commit into
Draft
Add AWSLambda0145 diagnostic for unregistered durable envelope types#2464GarrettBeatty wants to merge 1 commit into
GarrettBeatty wants to merge 1 commit into
Conversation
When a [DurableExecution] function registers the source-generator serializer (SourceGeneratorLambdaJsonSerializer<TContext>), the durable invocation envelope types DurableExecutionInvocationInput and DurableExecutionInvocationOutput must be registered on the JsonSerializerContext with [JsonSerializable]. Unlike the reflection-based DefaultLambdaJsonSerializer, the context only serializes types explicitly registered, so a missing registration fails only at invocation time. The generator now emits AWSLambda0145 (Warning) at build time when either envelope type is missing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a new build-time diagnostic AWSLambda0145 (Warning) to the Annotations source generator.
Motivation
With the Annotations model, a
[DurableExecution]function's generated handler has the signature:Users never see
DurableExecutionInvocationInput/DurableExecutionInvocationOutputin their own code — the generator introduces them. If the function registers the source-generator serializer (SourceGeneratorLambdaJsonSerializer<TContext>), the durable runtime (de)serializes that envelope through the user'sJsonSerializerContext. Unlike the reflection-basedDefaultLambdaJsonSerializer, a source-gen context only handles types explicitly registered via[JsonSerializable]. If the envelope types aren't registered, the function fails at invocation time with no build-time signal.This diagnostic surfaces the problem at build time, consistent with the other durable diagnostics (AWSLambda0142–0144).
Behavior
Emitted (Warning) only when all hold:
[DurableExecution], andSourceGeneratorLambdaJsonSerializer<TContext>, andTContext(walking its base contexts) does not register a given envelope type via[JsonSerializable(typeof(...))].One warning per missing envelope type. Silent for
DefaultLambdaJsonSerializer/ any non-source-gen serializer, and skipped if the durable types can't be resolved (package not referenced — other diagnostics cover that).Changes
TypeFullNames.cs: addSourceGeneratorLambdaJsonSerializer1andJsonSerializableAttribute` constants.DiagnosticDescriptors.cs: addDurableExecutionMissingSerializableEnvelope(AWSLambda0145, Warning).AnalyzerReleases.Unshipped.md: register the new rule.LambdaFunctionValidator.cs: addValidateDurableExecutionSerializerContext, called fromValidateDurableExecution.DurableExecutionSerializerContextDiagnosticsTests— both registered (no diagnostic), one missing, both missing, and DefaultLambdaJsonSerializer (no diagnostic).Amazon.Lambda.Annotations, Minor).Testing
dotnet build -c Releaseon the generator: clean.DurableExecution*generator tests pass (net10.0), including the 4 new ones.