forked from hashicorp/hcl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hclsyntax: Don't panic when function returns invalid ArgError
When a function returns a functions.ArgError it's supposed to set the argument index to a valid index within the range of the given argument slice. However, we typically try to be robust in the face of incorrectly-implemented functions, so rather than panicking in that case as we would've before we'll now return a slightly-less-precise error message. The "if i > len(e.Args)-1" case in the previous code here was actually trying to handle this situation before, but it didn't quite manage to do it because it was incorrectly referring to e.Args rather than "args" (so it couldn't take into account expanded arguments) and because it incorrectly assumed that there would always be more declared parameters than arguments, which is actually never true in any valid call. Now we'll handle out of range a little differently for variadic vs. non-variadic functions. For variadics we'll assume that the function was trying to talk about the variadic parameter and name that in the error message. For non-variadics we can't do anything special so we end up just treating it the same as any other error type, simply stating that the function call failed without naming a particular argument. Functions that end up in this error-handling codepath should still be fixed, because they'll likely end up returning a slightly confusing error message which doesn't accurately reflect the source of the problem. The goal here is just avoid a panic in that case.
- Loading branch information
1 parent
7348b6a
commit f6e7bb7
Showing
2 changed files
with
140 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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