Fix panic on obtaining provider schemas #1048
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes the LS panic reported in hashicorp/vscode-terraform#1213.
Stack trace:
Background
We have two jobs, one to obtain the provider schema via
terraform providers schema -json
and one to get the Terraform and provider versions viaterraform version -json
. We track provider schemas in a memdb table, and both jobs add their results to a schema entry in this table. Only the results of both jobs combined produce a usable schema.Since we delayed the execution of Terraform version in terraform-ls #1014, we can end up with a schema without a version in the table. The check whether a schema version matches the constrains panics in certain conditions. It panics for constraints like
>= 1.0.0
, but not1.0.0
.The introduction of
dependsOn
for jobs should avoid getting into a situation like this in the first place. The job for obtaining the schema, depends on the job for parsing the provider versions:terraform-ls/internal/indexer/walker.go
Lines 131 to 139 in 8a410a0