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

depsfile: Don't panic when lock file is unreadable #27250

Merged
merged 1 commit into from
Dec 16, 2020

Conversation

apparentlymart
Copy link
Contributor

Previously we were expecting that the *hcl.File would always be non-nil, even in error cases. That isn't always true, so now we'll be more robust about it and explicitly return an empty locks object in that case, along with the error diagnostics.

In particular this avoids a panic in a strange situation where the user created a directory where the lock file would normally go, and so this fixes #27144. There's no meaning to such a directory, so it would always be a mistake and so now we'll return an error message about it, rather than panicking as before.

The error message for the situation where the lock file is a directory is currently rather vague, but since it's HCL responsible for generating that message we can't easily fix that at this layer. Perhaps in future we can change HCL to have a specialized error message for that particular error situation, but for the sake of this commit the goal is only to stop the panic and return a normal error message.

@apparentlymart apparentlymart added bug crash cli v0.14 0.14-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged labels Dec 11, 2020
@apparentlymart apparentlymart requested a review from a team December 11, 2020 00:23
@apparentlymart apparentlymart self-assigned this Dec 11, 2020
@codecov
Copy link

codecov bot commented Dec 11, 2020

Codecov Report

Merging #27250 (24ec855) into master (c412935) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted Files Coverage Δ
internal/depsfile/locks_file.go 77.39% <100.00%> (+0.17%) ⬆️
states/statefile/version4.go 58.19% <0.00%> (+0.23%) ⬆️
dag/marshal.go 63.49% <0.00%> (+1.58%) ⬆️
terraform/node_resource_apply_instance.go 52.55% <0.00%> (+2.79%) ⬆️
internal/providercache/dir.go 73.46% <0.00%> (+6.12%) ⬆️

// This can never happen when Terraform is the one generating the
// lock file, but might arise if the user makes a directory with the
// lock file's name for some reason. (There is no actual reason to do
// so, so that would always be a mistake.)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this comment applies to this test case, copy & paste error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right you are! Thanks

Previously we were expecting that the *hcl.File would always be non-nil,
even in error cases. That isn't always true, so now we'll be more robust
about it and explicitly return an empty locks object in that case, along
with the error diagnostics.

In particular this avoids a panic in a strange situation where the user
created a directory where the lock file would normally go. There's no
meaning to such a directory, so it would always be a mistake and so now
we'll return an error message about it, rather than panicking as before.

The error message for the situation where the lock file is a directory is
currently not very specific, but since it's HCL responsible for generating
that message we can't really fix that at this layer. Perhaps in future
we can change HCL to have a specialized error message for that particular
error situation, but for the sake of this commit the goal is only to
stop the panic and return a normal error message.
@ghost
Copy link

ghost commented Jan 15, 2021

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.

@ghost ghost locked as resolved and limited conversation to collaborators Jan 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
0.14-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged bug cli crash
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic on 1.14 due to .terraform.lock.hcl being a folder
2 participants