-
Notifications
You must be signed in to change notification settings - Fork 131
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
base: main
Are you sure you want to change the base?
Conversation
existingDiags = existingDiags.Copy() | ||
} | ||
for fileName, diagnostic := range diags { | ||
existingDiags[ast.FilenameFromName(fileName)] = diagnostic |
There was a problem hiding this comment.
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.
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.
620360e
to
17bfb0a
Compare
There was a problem hiding this 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()
).
@@ -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= |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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
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