-
Notifications
You must be signed in to change notification settings - Fork 38
Open
Labels
Description
Describe the bug
I get the following when running this tool across many templates, using the parameters TemplateAnalyzer analyze-template infra/main.bicep --report-format Console
Error: An exception occurred while analyzing template /Users/anthonyshaw/projects/APICenter-Analyzer/infra/main.bicep
Exception details:
Microsoft.Azure.Templates.Analyzer.Core.TemplateAnalyzerException: Error while evaluating rules.
---> Microsoft.Azure.Templates.Analyzer.Core.TemplateAnalyzerException: Error while processing template.
---> Newtonsoft.Json.JsonSerializationException: Deserialized JSON type 'Newtonsoft.Json.Linq.JValue' is not compatible with expected type 'Newtonsoft.Json.Linq.JObject'. Path 'parameters.applicationInsightsName', line 1, position 3165.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateJToken(JsonReader reader, JsonContract contract)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)
at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType)
at Newtonsoft.Json.Linq.JToken.ToObject[T]()
at Microsoft.Azure.Templates.Analyzer.TemplateProcessor.ArmTemplateProcessor.PopulateParameters(String parameters)
at Microsoft.Azure.Templates.Analyzer.TemplateProcessor.ArmTemplateProcessor.ProcessTemplate(String parameters, String metadata)
at Microsoft.Azure.Templates.Analyzer.TemplateProcessor.ArmTemplateProcessor.ProcessTemplate(String parameters)
at Microsoft.Azure.Templates.Analyzer.Core.TemplateAnalyzer.AnalyzeAllIncludedTemplates(String populatedTemplate, String parameters, String templateFilePath, TemplateContext parentContext, String pathPrefix)
--- End of inner exception stack trace ---
at Microsoft.Azure.Templates.Analyzer.Core.TemplateAnalyzer.AnalyzeAllIncludedTemplates(String populatedTemplate, String parameters, String templateFilePath, TemplateContext parentContext, String pathPrefix)
at Microsoft.Azure.Templates.Analyzer.Core.TemplateAnalyzer.AnalyzeAllIncludedTemplates(String populatedTemplate, String parameters, String templateFilePath, TemplateContext parentContext, String pathPrefix)
--- End of inner exception stack trace ---
at Microsoft.Azure.Templates.Analyzer.Core.TemplateAnalyzer.AnalyzeAllIncludedTemplates(String populatedTemplate, String parameters, String templateFilePath, TemplateContext parentContext, String pathPrefix)
at Microsoft.Azure.Templates.Analyzer.Core.TemplateAnalyzer.AnalyzeTemplate(String template, String templateFilePath, String parameters)
at Microsoft.Azure.Templates.Analyzer.Cli.CommandLineParser.AnalyzeTemplate(TemplateAndParams templateAndParameters)
Execution summary:
Summary of the warnings:
1 instance of: An exception occurred while evaluating the properties of the resource named functionapp
1 instance of: An exception occurred while evaluating the properties of the resource named apicenteraccess
1 instance of: An exception occurred while evaluating the properties of the resource named apicenteraccessexist
1 instance of: The parsing of the template output named AZURE_FUNCTION_NAME failed
1 instance of: The parsing of the template output named primaryEndpoints failed
Summary of the errors:
1 instance of: An exception occurred while analyzing template /Users/anthonyshaw/projects/APICenter-Analyzer/infra/main.bicep
5 Warnings
1 Error
It stops analysing the template at that stage.
I put a breakpoint in Visual Studio with this project in debug mode to better understand it, the parameters it was evaluating look like this:
{
"name": "[if(not(empty(parameters('appServicePlanName'))), createObject('value', parameters('appServicePlanName')), createObject('value', format('{0}{1}', variables('abbrs').webServerFarms, variables('resourceToken'))))]",
"location": {
"value": "[parameters('location')]"
},
"tags": {
"value": "[variables('tags')]"
},
"sku": {
"value": {
"name": "Y1"
}
},
"kind": {
"value": "linux"
},
"parameters": {
"name": "[if(not(empty(parameters('appServicePlanName'))), createObject('value', parameters('appServicePlanName')), createObject('value', format('{0}{1}', variables('abbrs').webServerFarms, variables('resourceToken'))))]",
"location": {
"value": "[parameters('location')]"
},
"tags": {
"value": "[variables('tags')]"
},
"sku": {
"value": {
"name": "Y1"
}
},
"kind": {
"value": "linux"
}
},
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0"
}
It crashes because this line https://github.com/Azure/template-analyzer/blob/main/src/Analyzer.TemplateProcessor/ArmTemplateProcessor.cs#L549 assumes that the parameter is an object, but the name
parameter is a string with an expression inside it.
Expected behavior
see detail
Reproduction Steps
see detail
Environment
No response