Create an error type for unknown function diags#657
Merged
Conversation
apparentlymart
approved these changes
Feb 14, 2024
| // FunctionCallUnknown is an interface implemented by a value in the Extra | ||
| // field of some diagnostics to indicate when the error was caused by a call to | ||
| // an unknown function. | ||
| type FunctionCallUnknown interface { |
Contributor
There was a problem hiding this comment.
The existing "diagnostic extra" interface nearby here has "DiagExtra" at the end of its name to try to make it clear that it's there only for used in the "diagnostic extra" field. Should we do that here too?
(If we do end up finding another use of this interface that isn't related to "diagnostic extra" then we can presumably add another name covering the same methods to make it back-compatible, but I'm not imagining any specific reason why we might do that in future.)
Member
Author
There was a problem hiding this comment.
Yeah, that's a good point. I think I removed that at some point because this fell more natural to describe the error, but it does lose the context that it's only for the Extra field.
Now that we have namespaced functions, and implementations like Terraform can add functions based on configuration, the reason for an unknown function call name becomes a little less clear. Because functions are populated outside of the hcl package scope, there isn't enough context to provide a useful diagnostic to the user. We can create a new Diagnostic.Extra value for FunctionCallUnknownDiagExtra to indicate specifically when a diagnostic is created due to an unknown function name. This will carry back the namespace and function name for the caller to inspect, which will allow refinement of the diagnostic based on information only known to the caller.
67f9054 to
159a39d
Compare
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.
Now that we have namespaced functions, and implementations like Terraform can add functions based on configuration, the reason for an unknown function call name becomes a little less clear. Because functions are populated outside of the hcl package scope, there isn't enough context to provide a useful diagnostic to the user.
We can create a new
Diagnostic.Extravalue satisfying a newFunctionCallUnknownDiagExtrainterface, indicating specifically when a diagnostic is created due to an unknown function name. This will carry back the namespace and function name for the caller to inspect, which will allow refinement of the diagnostic based on information only known to the caller.