-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change exception type/message when project item does not exist #391
Conversation
Tests passed for netcoreapp2.0 and netcoreapp3.1, but I am not able to run the tests for net5.0 yet. |
@@ -108,7 +108,7 @@ public virtual async Task<RazorCodeDocument> CreateCodeDocumentAsync(RazorLightP | |||
|
|||
if (!projectItem.Exists) | |||
{ | |||
throw new InvalidOperationException($"Project can not find template with key {projectItem.Key}"); | |||
throw new InvalidOperationException($"RazorLightProjectItem with key {projectItem.Key} must exist"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use $"nameof(RazorLightProjectItem) of type {projectItem.GetType().FullName} with key {projectItem.Key} does not exist."
My rationale being that it would help when people ask for help to know exactly what type of RazorLightProjectItem they passed in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made the requested changes. I also added two additional tests since the new exception messages require that projectItem is not null.
@@ -71,7 +71,7 @@ public async Task<IGeneratedRazorTemplate> GenerateCodeAsync(RazorLightProjectIt | |||
|
|||
if (!projectItem.Exists) | |||
{ | |||
throw new TemplateNotFoundException($"Project can not find template with key {projectItem.Key}"); | |||
throw new InvalidOperationException($"RazorLightProjectItem with key {projectItem.Key} must exist"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use $"nameof(RazorLightProjectItem) of type {projectItem.GetType().FullName} with key {projectItem.Key} does not exist."
My rationale being that it would help when people ask for help to know exactly what type of RazorLightProjectItem they passed in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made the requested changes. I also added two additional tests since the new exception messages require that projectItem is not null.
Thanks. I will try to push this out tonight. |
Change exception type/message when project item does not exist
This is related to the discussion in #378
RazorSourceGenerator.GenerateCodeAsync(RazorLightProjectItem projectItem)
andRazorSourceGenerator.CreateCodeDocumentAsync(RazorLightProjectItem projectItem)
both accept aRazorLightProjectItem
with the precondition that the.Exists
property is true. Previously, when this precondition was not met,GenerateCodeAsync
threw aTemplateNotFoundException
whileCreateCodeDoucmentAsync
threw aInvalidOperationException
. The exception language and type (inGenerateCodeAsync
) made it sound like these methods are trying to "look up" a template, when in reality they are only checking theExists
property on the project item. These changes clarify the behavior of these methods and make the exception type consistent.