microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
744 stars 245 forks source link

[BUG] CodeCop Version 15 Strange Analyzer Error from app.json #5233

Closed ThomasBrendel closed 4 years ago

ThomasBrendel commented 5 years ago

Hello Team,

we found a strange Analyzer Error when having following code:

var ModifiedMsg: label 'You have modified %1.\'; UpdateMsg: label 'Do you want to update the lines?'

Question := StrSubstNo( ModifiedMsg + UpdateMsg, ChangedFieldName);

The CodeCop comes up with such a message:

image

You have no chance to find it in your code

atoader commented 5 years ago

Thanks for reporting this issue, Thomas! I have forwarded it to the team that implemented the rule.

MarcHansenMicrosoft commented 5 years ago

Hi @ThomasBrendel,

Is the error comming from the code you listed or from the app.json file?

Can you give us more of the call stack?

Thanks /Marc

ThomasBrendel commented 5 years ago

Hello,

the Error is from the code i have listed. Its because you have

ModifiedMsg + UpdateMsg

and you have only %1 parameter inside the Textmsg and combine that textmessage inside the SUBSTRNO.

If you combine both texts outside the function then all is fine. The Problem is that you have to seriously search, because the warningmessage shows only app.json, instead the position of the real problem (if that is a problem at all)

MarcHansenMicrosoft commented 5 years ago

Thanks

MarcHansenMicrosoft commented 5 years ago

Can you send more of the stack trace?

ThomasBrendel commented 5 years ago

{ "resource": "/c:/Users/tbrendel/Documents/AL/M365ConnectorJobStructureEditor/app.json", "owner": "_generated_diagnostic_collectionname#1", "code": "AD0001", "severity": 4, "message": "Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Design.Rule131StringParamsMustMatchPlaceholders' threw an exception of type 'System.NullReferenceException' with message 'System.NullReferenceException: Object reference not set to an instance of an object.\r\n at Microsoft.Dynamics.Nav.CodeCop.Design.Rule131StringParamsMustMatchPlaceholders.GetExpressionParamValue(IOperation expression) in F:\a\193\s\source\Prod\Microsoft.Dynamics.Nav.CodeCop\Design\Rule131StringParamsMustMatchPlaceholders.cs:line 105\r\n at Microsoft.Dynamics.Nav.CodeCop.Design.Rule131StringParamsMustMatchPlaceholders.AnalyzeInvocation(OperationAnalysisContext ctx) in F:\a\193\s\source\Prod\Microsoft.Dynamics.Nav.CodeCop\Design\Rule131StringParamsMustMatchPlaceholders.cs:line 75\r\n at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass53_1.b__1() in F:\a\193\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 763\r\n at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in F:\a\193\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1077'", "source": "AL", "startLineNumber": 1, "startColumn": 1, "endLineNumber": 1, "endColumn": 1 }

MarcHansenMicrosoft commented 4 years ago

Fixed in master