toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.51k stars 261 forks source link

Change exception type/message when project item does not exist #391

Closed maxbanas closed 3 years ago

maxbanas commented 3 years ago

This is related to the discussion in #378
RazorSourceGenerator.GenerateCodeAsync(RazorLightProjectItem projectItem) and RazorSourceGenerator.CreateCodeDocumentAsync(RazorLightProjectItem projectItem) both accept a RazorLightProjectItem with the precondition that the .Exists property is true. Previously, when this precondition was not met, GenerateCodeAsync threw a TemplateNotFoundException while CreateCodeDoucmentAsync threw a InvalidOperationException. The exception language and type (in GenerateCodeAsync) made it sound like these methods are trying to "look up" a template, when in reality they are only checking the Exists property on the project item. These changes clarify the behavior of these methods and make the exception type consistent.

maxbanas commented 3 years ago

Tests passed for netcoreapp2.0 and netcoreapp3.1, but I am not able to run the tests for net5.0 yet.

jzabroski commented 3 years ago

Thanks. I will try to push this out tonight.