hclparse/parser: open error fixes#644
Open
lbajolet-hashicorp wants to merge 2 commits intomainfrom
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As reported by a user on Packer (refer to issue hashicorp/packer#12726 for context), the
ParseHCLFilereturns a diagnostic that can be misleading in terms of the path presented because of the escaping that%qapplies.This, coupled with the fact that the
errreturned byos.ReadFileis not forwarded may cause some confusion among users, so we try to change this with that PR.