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

Wrong Analyzer for app.json #5835

Closed pri-kise closed 4 years ago

pri-kise commented 4 years ago

Describe the bug

With the new AL Language Extension I receiv the following warnings for the `app.json` file. 
    "resource": "/c:/Users/DummyTest/Documents/Repos/ALDemo/app.json",
    "owner": "_generated_diagnostic_collection_name_#0",
    "code": "AD0001",
    "severity": 4,
    "message": "Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Design.Rule087DoOnlyLowerPermissionsInsideTestProcedures' threw an exception of type 'System.InvalidCastException' with message 'System.InvalidCastException: Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.VariableListDeclarationSyntax' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.VariableDeclarationSyntax'.\r\n   at Microsoft.Dynamics.Nav.CodeCop.Design.Rule087DoOnlyLowerPermissionsInsideTestProcedures.AnalyzeVariableList(SyntaxNodeAnalysisContext ctx) in D:\\a\\1\\s\\source\\Prod\\Microsoft.Dynamics.Nav.CodeCop\\Design\\Rule087DoOnlyLowerPermissionsInsideTestProcedures.cs:line 45\r\n   at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass52_1.<ExecuteSyntaxNodeAction>b__1() in D:\\a\\1\\s\\source\\Prod\\Microsoft.Dynamics.Nav.CodeAnalysis\\DiagnosticAnalyzer\\AnalyzerExecutor.cs:line 742\r\n   at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in D:\\a\\1\\s\\source\\Prod\\Microsoft.Dynamics.Nav.CodeAnalysis\\DiagnosticAnalyzer\\AnalyzerExecutor.cs:line 1099'",
    "source": "AL",
    "startLineNumber": 1,
    "startColumn": 1,
    "endLineNumber": 1,
    "endColumn": 1
}
{
    "resource": "/c:/Users/DummyTest/Documents/Repos/ALDemo/app.json",
    "owner": "_generated_diagnostic_collection_name_#0",
    "code": "AD0001",
    "severity": 4,
    "message": "Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Design.Rule205VariablesMustAlwaysBeInitialized' threw an exception of type 'System.InvalidCastException' with message 'System.InvalidCastException: Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.VariableListDeclarationSyntax' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.VariableDeclarationSyntax'.\r\n   at Microsoft.Dynamics.Nav.CodeCop.Design.Rule205VariablesMustAlwaysBeInitialized.InitializeGlobalVariablesAnalyzer(SyntaxNodeAnalysisContext syntaxNodeAnalysisContext) in D:\\a\\1\\s\\source\\Prod\\Microsoft.Dynamics.Nav.CodeCop\\Design\\Rule205VariablesMustAlwaysBeInitialized.cs:line 105\r\n   at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass52_1.<ExecuteSyntaxNodeAction>b__1() in D:\\a\\1\\s\\source\\Prod\\Microsoft.Dynamics.Nav.CodeAnalysis\\DiagnosticAnalyzer\\AnalyzerExecutor.cs:line 742\r\n   at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in D:\\a\\1\\s\\source\\Prod\\Microsoft.Dynamics.Nav.CodeAnalysis\\DiagnosticAnalyzer\\AnalyzerExecutor.cs:line 1099'",
    "source": "AL",
    "startLineNumber": 1,
    "startColumn": 1,
    "endLineNumber": 1,
    "endColumn": 1
}

To Reproduce I have no idea how this can be reproduced.

Expected behavior These Codecops shouldn't evaluate the app.json file.

Screenshots

5. Versions:

salgiza commented 4 years ago

If it helps: when the analyzer crashes it always says that the error is in the app.json file, instead of pointing to the real .al file that it was parsing when it crashed (unfortunately, I've been there a lot of times).

So, you seem to have found a bug in the analyzer (it should never crash), but it is probably unrelated to the app.json. You might want to remove *.al files from the app until the errors disappear, to try to find what in particular is causing these crashes.

kasperdj commented 4 years ago

Any progress on this issue. Currently when there is a "runtime" error in the CodeCop Analyzer referencing app.json the CodeCop stops working and we will not see the error before our build pipeline fails. At the moment we have a lot over overhead due to this issue.

atoader commented 4 years ago

@MarcHansenMicrosoft can you take a look?

MarcHansenMicrosoft commented 4 years ago

CodeCop does run on app.json as well as code.

Could provide a sample repro solution, so we can investigate the issue?

salgiza commented 4 years ago

@MarcHansenMicrosoft Regardless of whether this particular error is due to the app.json or not, could it be possible to catch error exceptions in CodeCop, so that when it crashes it tells you which file it was parsing? (instead of always pointing to the app.json)

MarcHansenMicrosoft commented 4 years ago

@atoader that is more a question for you.

ffulconis-pdw commented 4 years ago

Hi, I don't know if this can help or if really related but I encountered same kind of error linked to App.json recently. I did not succeed reproducing in fresh new hello world project but can observe it in our own. In my case It came from declaring same type variables on single line. Once I rollback to one line by variable the error desapeared.

AL Language 5.0.254558, BC 16.0.11240.12474

Here is the error received when variables are declared on same Line: Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Design.Rule205VariablesMustAlwaysBeInitialized' threw an exception of type 'System.InvalidCastException' with message 'System.InvalidCastException: Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.VariableListDeclarationSyntax' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.VariableDeclarationSyntax'. at Microsoft.Dynamics.Nav.CodeCop.Design.Rule205VariablesMustAlwaysBeInitialized.InitializeGlobalVariablesAnalyzer(SyntaxNodeAnalysisContext syntaxNodeAnalysisContext) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeCop\Design\Rule205VariablesMustAlwaysBeInitialized.cs:line 105 at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass52_1.b__1() in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 742 at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1099'

kasperdj commented 4 years ago

I can provide an al project with the problem if you setup a private file transfer workspace and send this link to the workspace to krj@elbek-vejrup.dk

kalberes commented 4 years ago

@MarcHansenMicrosoft the issue maybe here that the codeanalyzer in place does not read correctly the diagnostic source file location.

PaulIvan commented 4 years ago

Thank your for reporting this issue. I am closing it as it looks like a duplicate of #5889. Feel free to contribute on the issue linked.