Ballerina-lang: Provide a convenient way to log errors from compiler extensions

Created on 24 Nov 2020  路  4Comments  路  Source: ballerina-platform/ballerina-lang

Description:
Currently we expose a public Diagnostic API to represent diagnostics, and a DiagnosticLog API as a convenient way to log errors.

However, the DiagnosticLog doesn't have a default/common implementation. Hence every compiler extension needs to implement their own DiagnosticLog, in-order to log errors. This not only adds extra work to the extension developer, but also results in a lot of duplicate codes, as well as inconsistency in the errors.

Suggestion is to:

  • Provide a default/common impl of the DiagnosticLog
  • One should be able to initialize the DiagnosticLog by providing the properties file that has the error message templates.
  • If someone needs to change the behaviour of some part of the logger, they can extend and use it.

With this, to log errors from a compiler extension, the developer only needs to:

  • Create the error codes
  • Create the error message templates (properties file)
AreCompilerExtensions AreDiagnosticAPI AreDiagnostics PrioritHigh TeaCompilerFE TypImprovement

All 4 comments

As part of this, we should also look at the possibility of exposing some of the fine-grained APIs in the BLangDiagnosticLog from the DiagnosticLog as well.

For the compiler plugins, we are passing a diagnostic logger instance to its init() method though?

@pubudu91 the problem is, if they wants to add any extension-specific errors, then they have to add those to compiler's error messages template (compiler.properties file). Ideally error templates should be maintained by each extension.

I think we need to expose some APIs at the DiagnosticLog as well. This would be a cleaner approach when it comes to the extensions with custom Error codes and etc. As @SupunS has suggested these should be extendable.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NipunaMarcus picture NipunaMarcus  路  5Comments

daneshk picture daneshk  路  5Comments

hemikak picture hemikak  路  5Comments

hemikak picture hemikak  路  5Comments

mgabalins picture mgabalins  路  3Comments