ballerina-lang
ballerina-lang copied to clipboard
Misleading diagnostic ordering when resolving packages
Consider a scenario where I have specified a package version in the Ballerina.toml which is not available locally, but I have included the property repository=local. e.g.,
[[dependency]]
org = "pubudu"
name = "policy_validator"
version = "0.3.3"
repository="local"
In the above case, 0.3.3 is not available locally but it is there in Central. When I run the package, I get the following:
Compiling source
pubudu/addHeader:2.0.0
pubudu/policy_validator:0.3.3 [central.ballerina.io -> home repo] 100% [====================================================================================================================] 12/12 KB (0:00:00 / 0:00:00)
pubudu/policy_validator:0.3.3 pulled from central successfully
Generating 'policy-meta.json' file...
WARNING [Ballerina.toml:(10:1,14:19)] Dependency version (0.3.3) cannot be found in the local repository. org: `pubudu` name: policy_validator
Although there was this warning, it ran without any issue. The ordering of the events/diagnostics is a bit confusing here. When I saw that the package was pulled successfully, the expectation was that now it's available locally (it was available now). But when the compiler gave the warning about not being able to find the package locally, I thought there must've been something wrong in pulling the package or that the package wasn't getting resolved properly.
Had a chat with @azinneera and she pointed out that it's just that the diagnostic is getting printed later. It would be better if these sort of diagnostics are printed first, before attempting to pull the package from Central. e.g.,
Compiling source
pubudu/addHeader:2.0.0
WARNING [Ballerina.toml:(10:1,14:19)] Dependency version (0.3.3) cannot be found in the local repository. org: `pubudu` name: policy_validator
pubudu/policy_validator:0.3.3 [central.ballerina.io -> home repo] 100% [====================================================================================================================] 12/12 KB (0:00:00 / 0:00:00)
pubudu/policy_validator:0.3.3 pulled from central successfully
Generating 'policy-meta.json' file...
Basically the requirement is, clearly communicate to the user that it'll try and fetch the package from Central if it's not available locally.
The logging in the above scneario happens as follows.
- Within
CompileTask, we callPackageResolution. - As a part of the package resolution, we create the blended manifest. During the blended manifest creation we add the
Dependency version (0.3.3) cannot be found in the local repository. org:pubuduname: policy_validatordiagnostic. - Then we go on to look for the dependency in the Central. There we print the logs related to package pulling.
- After all that, in the CompileTask, we print all the available diagnostics related to package compilation.
Since we are printing the diagnostics at the end, order confusion occurs. We can't log the diagnostics at the time of diagnostic creation since the LS is also using the same APIs.
As per an offline discussion with @azinneera, this can be fixed with a newer design for how we print the diagnostics. One possible solution is to have a watcher that logs the diagnostics at the time of occurring. This needs to be discussed further.