templating
templating copied to clipboard
Propagate Template Authoring errors via TemplateAuthoringException and TemplateIssueDetected status
Current behavior:
Many template authoring errors end up being hidden under 'Not Found' errors - as TemplateAuthoringException is not properly thrown/handled/propagated
Example:
> dotnet new invalid01
Error: Failed to load template from "invalid01\.template.config/template.json".
Details: Newtonsoft.Json.JsonReaderException: JsonToken EndObject is not valid for closing JsonType Array. Path 'guids', line 18, position 1.
at Newtonsoft.Json.JsonReader.ValidateEnd(JsonToken endToken)
at Newtonsoft.Json.JsonReader.SetToken(JsonToken newToken, Object value, Boolean updateIndex)
at Newtonsoft.Json.JsonTextReader.ParsePostValue(Boolean ignoreComments)
at Newtonsoft.Json.JsonTextReader.Read()
at Newtonsoft.Json.Linq.JContainer.ReadContentFrom(JsonReader r, JsonLoadSettings settings)
at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(JsonReader reader, JsonLoadSettings options)
at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader)
at Microsoft.TemplateEngine.JExtensions.ReadJObjectFromIFile(IFile file) in C:\src\templating\src\Shared\JExtensions.cs:line 306
at Microsoft.TemplateEngine.Orchestrator.RunnableProjects.RunnableProjectConfig..ctor(IEngineEnvironmentSettings settings, IGenerator generator, IFile templateFile, IFile hostConfigFile, IFile localeConfigFile, String baselineName) in C:\src\templating\src\Microsoft.TemplateEngine.Orchestrator.RunnableProjects\RunnableProjectConfig.cs:line 78
at Microsoft.TemplateEngine.Orchestrator.RunnableProjects.RunnableProjectGenerator.TryGetTemplateFromConfigInfo(IFileSystemInfo templateFileConfig, ITemplate& template, IFileSystemInfo localeFileConfig, IFile hostTemplateConfigFile, String baselineName) in C:\src\templating\src\Microsoft.TemplateEngine.Orchestrator.RunnableProjects\RunnableProjectGenerator.cs:line 259
Unable to locate the specified template content, the template cache may be corrupted. Try running 'dotnet Microsoft.TemplateEngine.Cli.Commands.TemplateCommandArgs --debug:reinit' to fix the issue.
For details on the exit code, refer to https://aka.ms/templating-exit-codes#103
Expected behavior:
Issues in parsing template files should be propagated via TemplateAuthoringException, that gets eventually translated to TemplateIssueDetected status and appropriate exit code.