Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(TFECO-7637) Raise HCL diagnostics #1850

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

(TFECO-7637) Raise HCL diagnostics #1850

wants to merge 4 commits into from

Conversation

jpogran
Copy link
Contributor

@jpogran jpogran commented Oct 17, 2024

This change updates the stack metadata loading to merge the new diagnostics with the existing ones. This is necessary to ensure that we don't lose any diagnostics that were previously reported.

Needs hashicorp/terraform-schema#412

@jpogran jpogran self-assigned this Oct 17, 2024
existingDiags = existingDiags.Copy()
}
for fileName, diagnostic := range diags {
existingDiags[ast.FilenameFromName(fileName)] = diagnostic
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will overwrite any existing diagnostics for the file. We could either add a new diagnostics source for the early decoder or implement an .Extend method to append them.

@jpogran jpogran changed the title Raise HCL diagnostics (TFECO-7637) Raise HCL diagnostics Nov 4, 2024
This change updates the stack metadata loading to merge the new diagnostics with the existing ones. This is necessary to ensure that we don't lose any diagnostics that were previously reported.
@jpogran jpogran requested a review from dbanck November 7, 2024 21:54
@jpogran jpogran marked this pull request as ready for review November 8, 2024 16:02
@jpogran jpogran requested a review from a team as a code owner November 8, 2024 16:02
Copy link
Member

@dbanck dbanck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed a few things when I tried to use this feature. These don't require changes to this PR, but rather to terraform-schema. I am sorry that I missed them during the review of hashicorp/terraform-schema#412 and am only bringing them up now.

Maybe we can add more test cases to the decoder in terraform-schema to cover them.


We need to check that req.Source and req.VersionConstraints are both not null when iterating over the requirements, to avoid crashing due to a null pointer dereference.

Both diagnostic messages contain nil because we are using an empty field in our string (e.g. pr.source instead of source.AsString()).

CleanShot 2024-11-11 at 11 59 41@2x

CleanShot 2024-11-11 at 11 59 22@2x

@@ -235,6 +235,8 @@ github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTV
github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM=
github.com/hashicorp/terraform-schema v0.0.0-20241030161413-0438899ff948 h1:2yw+7HPYOAEFafRpcw7BOtX9svWmXdc8sK5sSLZIjiI=
github.com/hashicorp/terraform-schema v0.0.0-20241030161413-0438899ff948/go.mod h1:cA6LcD9EWWwgG3ZsZx+Fvyvgil6LYxTl3bknC8LF0B8=
github.com/hashicorp/terraform-schema v0.0.0-20241105102030-8286681d49d5 h1:/VZpxQ/eiKILd1Qm92Ge50VdsWieGGBvoP5obtg9flU=
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run go mod tidy

@@ -34,13 +36,36 @@ func LoadStackMetadata(ctx context.Context, stackStore *state.StackStore, stackP
return err
}

meta, diags := earlydecoder.LoadStack(record.Path(), record.ParsedFiles.AsMap())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LS panics when encountering an invalid source or version constraint:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x101084860]

goroutine 52 [running]:
github.com/hashicorp/terraform-schema/earlydecoder/stacks.LoadStack({0x140003e4237, 0x3b}, 0x14005e60930)
	/Users/daniel.banck/Projects/terraform-schema/earlydecoder/stacks/decoder.go:52 +0x670
github.com/hashicorp/terraform-ls/internal/features/stacks/jobs.LoadStackMetadata({0x102151988, 0x14005e60240}, 0x14000449560, {0x140068cd2c7, 0x3b})
	/Users/daniel.banck/Projects/terraform-ls/internal/features/stacks/jobs/metadata.go:39 +0x1e4
github.com/hashicorp/terraform-ls/internal/features/stacks.(*StacksFeature).decodeStack.func2({0x102151988, 0x14005e60240})
	/Users/daniel.banck/Projects/terraform-ls/internal/features/stacks/events.go:207 +0x60
github.com/hashicorp/terraform-ls/internal/scheduler.(*Scheduler).eval(0x14000448d50, {0x1021519c0, 0x140003d4460})
	/Users/daniel.banck/Projects/terraform-ls/internal/scheduler/scheduler.go:95 +0x8b4
created by github.com/hashicorp/terraform-ls/internal/scheduler.(*Scheduler).Start in goroutine 49
	/Users/daniel.banck/Projects/terraform-ls/internal/scheduler/scheduler.go:57 +0x224

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants