You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, TFLint will stop immediately and return an error if an error occurs on the way:
$ tflintFailed to check ruleset; Failed to check `azurerm_lb_probe_invalid_protocol` rule: main.tf:6,53-72: Invalid template interpolation value; The expression result is null. Cannot include a null value in a string template.
However, if multiple problems exist, you need to run TFLint multiple times until all errors are resolved. This is inefficient.
Fortunately, HCL parse errors (hcl.Diagnostics) already support multiple error handling:
Consideration should be given to how hcl.Diagnostics should be treated. hcl.Diagnostics can already handle multiple errors, but not all contexts over the wire protocol (e.g. EvalContext, Extra). Maybe we should invent our own error representation like tfdiags.
Introduction
Currently, TFLint will stop immediately and return an error if an error occurs on the way:
However, if multiple problems exist, you need to run TFLint multiple times until all errors are resolved. This is inefficient.
Fortunately, HCL parse errors (
hcl.Diagnostics
) already support multiple error handling:tflint/formatter/pretty.go
Lines 93 to 97 in 16e0218
This proposal mainly focuses on multiple error handling otherwise (especially errors returned by plugins).
See also #1665
Proposal
Change the plugin interface to allow multiple errors to be returned.
google.golang.org/grpc/status.WithDetails
allows us to attach multiple pieces of information to the status code, so we might be able to take advantage of this. FYI, the SDK already uses this mechanism to propagate application errors:https://github.com/terraform-linters/tflint-plugin-sdk/blob/v0.15.0/plugin/toproto/toproto.go#L226-L254
https://github.com/terraform-linters/tflint-plugin-sdk/blob/v0.15.0/plugin/fromproto/fromproto.go#L283-L321
When the
Check
returns an error, the SDK follows a convention to split it into multiple errors and turn them into status details. As the convention,errors.Join
, introduced in Go 1.20, is a good option.https://github.com/terraform-linters/tflint-plugin-sdk/blob/v0.15.0/plugin/host2plugin/server.go#L119
Consideration should be given to how
hcl.Diagnostics
should be treated.hcl.Diagnostics
can already handle multiple errors, but not all contexts over the wire protocol (e.g.EvalContext
,Extra
). Maybe we should invent our own error representation liketfdiags
.References
The text was updated successfully, but these errors were encountered: