[Analyzer] Flagging issues in logger message templates w/ incomplete braces pairs #101698
Labels
api-ready-for-review
API is ready for review, it is NOT ready for implementation
area-Extensions-Logging
code-analyzer
Marks an issue that suggests a Roslyn analyzer
Milestone
Posting this issue to this repo as per the suggestion of @tarekgh
dotnet/roslyn-analyzers#7285
dotnet/roslyn-analyzers#7286
tldr: Invalid braces in a message template aren't caught by
CA2017
, and when encountered lead to runtime exceptions.The PR and issues (linked and relevant snippets below) go about introducing a new analyzer
CA2023
because the changes introduced in some ways change the existing "meaning" ofCA2017
. Additionally this seems like it should probably be a compiler error rather than warning since otherwise a runtime exception occurs - though tbf i don't recall if having too few or too many message templateparams
lead to the same thing or notSuggested category: Reliability (and related to) https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2017
Suggested severity: warning (https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-options#severity-level)
Issue:
malformed message template strings for at a minimum logged messages should be throwing compiler errors IMO, rather than the current runtime errors seen with .net8.
Repro:
https://github.com/Kritner/MessageTemplateNet8
Yeah so it's weird... we're not
NoWarn
ing against this particular "CA2017", but we don't get the string template being flagged as a CA2017... I can easily make the CA2017 appear (and get a compiler error yay) if I change...to
More relevant comments:
dotnet/roslyn-analyzers#7285 (comment)
dotnet/roslyn-analyzers#7285 (comment)
dotnet/roslyn-analyzers#7286 (comment)
The text was updated successfully, but these errors were encountered: