-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Conversation
Codecov Report
|
internal/depsfile/locks_file_test.go
Outdated
// 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.) |
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 don't think this comment applies to this test case, copy & paste error?
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.
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.
7ba5c96
to
24ec855
Compare
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. |
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.