diff --git a/docs/analyzer-rules/AZFW0013.md b/docs/analyzer-rules/AZFW0013.md new file mode 100644 index 000000000..c09223c31 --- /dev/null +++ b/docs/analyzer-rules/AZFW0013.md @@ -0,0 +1,25 @@ +# AZFW0013: Unable to parse binding argument + +| | Value | +|-|-| +| **Rule ID** |AZFW0013| +| **Category** |[AzureFunctionsSyntax]| +| **Severity** |Error| + +## Cause + +This rule is triggered when a binding attribute argument is an invalid or null value. + +## Rule description + +[Attributes](https://learn.microsoft.com/en-us/dotnet/csharp/advanced-topics/reflection-and-attributes/) are used to define bindings, and the function metadata generator parses the arguments passed into these attributes to generate binding information during start up. + +If the arguments passed in are invalid for any reason (such as being null), this rule is enforced. + +## How to fix violations + +Review the binding attribute. + +## When to suppress warnings + +This rule should not be suppressed because this error will prevent your functions from running. diff --git a/sdk/Sdk.Generators/DiagnosticDescriptors.cs b/sdk/Sdk.Generators/DiagnosticDescriptors.cs index 2ebf9408a..9aaca2a6b 100644 --- a/sdk/Sdk.Generators/DiagnosticDescriptors.cs +++ b/sdk/Sdk.Generators/DiagnosticDescriptors.cs @@ -62,5 +62,12 @@ private static DiagnosticDescriptor Create(string id, string title, string messa messageFormat: "Invalid use of a retry attribute. Check that the attribute is used on a trigger that supports function-level retry.", category: "FunctionMetadataGeneration", severity: DiagnosticSeverity.Error); + public static DiagnosticDescriptor InvalidBindingAttributeArgument { get; } + = Create(id: "AZFW0013", + title: "Invalid argument in binding attribute.", + messageFormat: "Invalid argument passed in binding attribute. Check that the argument is not null.", + category: "FunctionMetadataGeneration", + severity: DiagnosticSeverity.Error); + } } diff --git a/sdk/Sdk.Generators/FunctionMetadataProviderGenerator/FunctionMetadataProviderGenerator.Parser.cs b/sdk/Sdk.Generators/FunctionMetadataProviderGenerator/FunctionMetadataProviderGenerator.Parser.cs index 5ba6d02c7..8c0d1caf6 100644 --- a/sdk/Sdk.Generators/FunctionMetadataProviderGenerator/FunctionMetadataProviderGenerator.Parser.cs +++ b/sdk/Sdk.Generators/FunctionMetadataProviderGenerator/FunctionMetadataProviderGenerator.Parser.cs @@ -632,7 +632,8 @@ private bool TryGetAttributeProperties(AttributeData attributeData, Location? at } else { - // TODO: Log diagnostic error + _context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.InvalidBindingAttributeArgument, attribLocation)); + return false; } } } @@ -690,7 +691,8 @@ private bool TryLoadConstructorArguments(AttributeData attributeData, IDictionar } else { - // TODO: Log diagnostic error + _context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.InvalidBindingAttributeArgument, attributeLocation)); + return false; } } diff --git a/sdk/release_notes.md b/sdk/release_notes.md index 5a99a0a84..7ba2857c9 100644 --- a/sdk/release_notes.md +++ b/sdk/release_notes.md @@ -14,4 +14,5 @@ ### Microsoft.Azure.Functions.Worker.Sdk.Generators -- Parse named arguments by type (#1877) \ No newline at end of file +- Parse named arguments by type (#1877) +- Add diagnostic descriptor logs for parsing binding arguments in source gen (#1882)