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

Error when a symlink with ".tfvars" extension is created inside a workspace #957

Closed
divergentdave opened this issue Jun 17, 2022 · 10 comments · Fixed by #968
Closed

Error when a symlink with ".tfvars" extension is created inside a workspace #957

divergentdave opened this issue Jun 17, 2022 · 10 comments · Fixed by #968
Assignees
Labels
bug Something isn't working
Milestone

Comments

@divergentdave
Copy link

Versions

Extension

v2.23.0

VS Code

1.68.1

Operating System

Ubuntu 20.04.4 LTS

Terraform Version

Terraform v1.2.3
on linux_amd64

Steps To Reproduce

Create a valid symlink with a filename that ends in .tfvars while VS Code is open, in a directory that it is watching.

Expected Behavior

No error or warning.

Actual Behavior

A notification that says "Unable to update "/path/to/.current_environment.auto.tfvars": filetype not supported. This is likely a bug which should be reported."

Additional context

I have tooling in my project that creates a symlink with an .auto.tfvars extension, pointing to a .tfvars file. (The Terraform CLI has worked fine with this setup) Whenever this symlink is recreated, I see a notification in VS Code with the above error.

@divergentdave divergentdave added the bug Something isn't working label Jun 17, 2022
@radeksimko
Copy link
Member

@divergentdave Thank you for the report.

This looks like a bug indeed - it looks like we don't account for symlinks. I will transfer it to the LS repository as that's where the bug will need to be fixed.

@radeksimko radeksimko transferred this issue from hashicorp/vscode-terraform Jun 17, 2022
@radeksimko
Copy link
Member

I would have thought fi.Name() here just returns the filename but it appears that the behaviour for symlinks just differs from a regular file 🤔

if !ast.IsModuleFilename(fi.Name()) && !ast.IsVarsFilename(fi.Name()) {
jrpc2.ServerFromContext(ctx).Notify(ctx, "window/showMessage", &lsp.ShowMessageParams{
Type: lsp.Warning,
Message: fmt.Sprintf("Unable to update %q: filetype not supported. "+
"This is likely a bug which should be reported.", rawPath),
})
return nil, ErrorSkip
}

@radeksimko radeksimko added this to the v0.29.0 milestone Jun 17, 2022
@radeksimko radeksimko self-assigned this Jun 23, 2022
@radeksimko
Copy link
Member

@divergentdave I tried to reproduce this without much luck. The logic seems to be working as expected in that even symlinks get reflected correctly in my local environment (macOS Monterey 12.4, Apple M1 Pro, Extension v2.23.0).

Screen.Recording.2022-06-24.at.12.31.11.mov

Full repro steps I tried:

variable "alpha" {
  type = string
}

variable "beta" {
  type = number
}

output "example" {
  value = "${var.alpha} / ${var.beta}"
}

test.tfvars (one level above the VS Code workspace)

alpha = "foobar"
beta  = 42

within the VS Code workspace

ln -s ../test.tfvars ./terraform.tfvars

Is there any chance the notifications show a different file? If not - could you provide a repro case as a sequence of steps, and/or possibly recording?

Thanks!

@radeksimko radeksimko removed this from the v0.29.0 milestone Jun 24, 2022
@radeksimko radeksimko added question Further information is requested waiting-response and removed bug Something isn't working labels Jun 24, 2022
@radeksimko
Copy link
Member

Could you also provide any (custom) settings you have set for the Terraform extension? It shouldn't matter as the extension controls what files are watched internally, but it would be helpful just in case there's something different between our environments.

@radeksimko
Copy link
Member

As an aside - I can believe that there is possibly a bug involving symlinks, I also filed #241 some time ago and I'm aware that we don't evaluate symlinks in various places, but I still wasn't able to come up with any repro case that would demonstrate any particular bug.

@radeksimko radeksimko added bug Something isn't working and removed question Further information is requested labels Jun 24, 2022
@divergentdave
Copy link
Author

I don't have any non-default extension settings configured. I have extension version v2.23.0 installed as well. Here's a minimal reproduction, as a bash script, with a screen recording of it in action. It seems that the leading . in the link name is required for reproduction, as well as the directory layout. I wonder if our differing operating systems could be part of the cause as well.

#!/bin/bash
echo 'terraform {}' > main.tf
echo 'a = 1' > vars.tfvars
mkdir dir
code .
read -s -p "Press enter to continue..." ; echo
ln -s ../vars.tfvars dir/.link.tfvars
screen-recording.mp4

@radeksimko
Copy link
Member

Reproduced! Thank you for the prompt response with repro steps - these helped.

Screenshot 2022-06-24 at 13 26 59

I will dig further to see what's causing it.

@radeksimko
Copy link
Member

I think I found the culprit

func isIgnoredFile(name string) bool {
return strings.HasPrefix(name, ".") || // Unix-like hidden files

@radeksimko
Copy link
Member

Fix now pending review in #968

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants