Al: Please improve exceptions

Created on 16 May 2020  路  5Comments  路  Source: microsoft/AL

It would be nice, if the AL Language Extension would produce more human readable error messages.

Please add more information, e.g. which AL file and which line this exception occurred, so I'm able to produce a proper bug report here.

Currently both exceptions point to the app.json, which I can exclude by the class name Rule087DoOnlyLowerPermissionsInsideTestProcedures and Rule205VariablesMustAlwaysBeInitialized.

{
    "resource": "/c:/Users/myuser/source/repos/MyApp/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/myuser/source/repos/MyApp/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
}
enhancement

All 5 comments

There are various bugs with things being attributed to app.json when they shouldn't. Repros for these might help MS fix that.

This seems more like a systemic problem; these exceptions never give the file that they are triggered by so the only way to find them is some sort of project bisection. This is not really reasonable (currently for me 500 files and 6347 files -- a baseapp with about half the changes moved into another extension).

It should be pretty easy for Microsoft to have the exception handler (carefully) rummage around for at least a source file; hopefully a line number too.

This is a good point! The main challenge is that these rules do not run on a file or even an object, they are decoupled from that concept. We'll see what we can do

Object Type and Object No. would also help

I think this should me marked as bug, since theses errors let pipelines crash.

Was this page helpful?
0 / 5 - 0 ratings