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

hclparse/parser: open error fixes #644

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

Conversation

lbajolet-hashicorp
Copy link

As reported by a user on Packer (refer to issue hashicorp/packer#12726 for context), the ParseHCLFile returns a diagnostic that can be misleading in terms of the path presented because of the escaping that %q applies.
This, coupled with the fact that the err returned by os.ReadFile is not forwarded may cause some confusion among users, so we try to change this with that PR.

When the hclparse's `Parser' attempts to open a file, and fails to do
so, we return a message that exposes the path with the `%s'
format-string specifier.

This specifier however duplicates the `\' in the path given, which on
Windows environments is common as it is the default delimiter between
directories.

As an alternative, Go offers the `%#q' specifier for format-strings,
which does not escape sequences as if they were go code, but instead
uses the alternative multiline syntax with '`', which leads to paths
not being over-escaped.
When a file fails to be read from disk, we return an error, but we don't
include the real problem in the hcl.Diagnostics returned to the caller,
which can be problematic in order to understand why reading failed.
This commit fixes this problem by including the verbatim error message
in the Details of the returned diag.
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.

None yet

1 participant