AL icon indicating copy to clipboard operation
AL copied to clipboard

Wrong Analyzer for app.json

Open pri-kise opened this issue 6 years ago • 10 comments

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:

  • AL Language: 5.0.254558
  • Business Central: DE Business Central 16.0 (Plattform 16.0.11233.12061 + Application 16.0.12076.0)

pri-kise avatar Apr 24 '20 10:04 pri-kise

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.

salgiza avatar Apr 28 '20 11:04 salgiza

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.

kasperdj avatar May 01 '20 10:05 kasperdj

@MarcHansenMicrosoft can you take a look?

atoader avatar May 05 '20 19:05 atoader

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

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

MarcHansenMicrosoft avatar May 06 '20 11:05 MarcHansenMicrosoft

@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)

salgiza avatar May 06 '20 11:05 salgiza

@atoader that is more a question for you.

MarcHansenMicrosoft avatar May 06 '20 11:05 MarcHansenMicrosoft

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'

ffulconis-pdw avatar May 06 '20 11:05 ffulconis-pdw

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 [email protected]

kasperdj avatar May 06 '20 11:05 kasperdj

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

kalberes avatar May 12 '20 14:05 kalberes

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.

PaulIvan avatar Oct 16 '20 13:10 PaulIvan