Skip to content

Commit 7b23e20

Browse files
authored
Deprecate EnsureNoError helper (#236)
1 parent dd804b3 commit 7b23e20

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

helper/runner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ func (r *Runner) EmitIssue(rule tflint.Rule, message string, location hcl.Range)
265265
}
266266

267267
// EnsureNoError is a method that simply runs a function if there is no error.
268+
//
269+
// Deprecated: Use errors.Is() instead to determine which errors can be ignored.
268270
func (r *Runner) EnsureNoError(err error, proc func() error) error {
269271
if err == nil {
270272
return proc()

plugin/plugin2host/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ func (c *GRPCClient) EmitIssue(rule tflint.Rule, message string, location hcl.Ra
367367

368368
// EnsureNoError is a helper for error handling. Depending on the type of error generated by EvaluateExpr,
369369
// determine whether to exit, skip, or continue. If it is continued, the passed function will be executed.
370+
//
371+
// Deprecated: Use errors.Is() instead to determine which errors can be ignored.
370372
func (*GRPCClient) EnsureNoError(err error, proc func() error) error {
371373
if err == nil {
372374
return proc()

tflint/errors.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ import (
55
)
66

77
// List of errors returned by TFLint.
8-
// It's possible to get this error from a plugin, but the error handling is hidden
9-
// inside the plugin system, so you usually don't have to worry about it.
108
var (
11-
// ErrUnknownValue is an error when an unknown value is referenced
9+
// ErrUnknownValue is an error that occurs when decoding an unknown value to a Go value.
1210
ErrUnknownValue = errors.New("unknown value found")
13-
// ErrNullValue is an error when null value is referenced
11+
// ErrNullValue is an error that occurs when decoding null to a Go value.
1412
ErrNullValue = errors.New("null value found")
15-
// ErrUnevaluable is an error when a received expression has unevaluable references.
13+
// ErrUnevaluable is an error that occurs when decoding an unevaluable value to a Go value.
14+
//
1615
// Deprecated: This error is no longer returned since TFLint v0.41.
1716
ErrUnevaluable = errors.New("")
18-
// ErrSensitive is an error when a received expression contains a sensitive value.
17+
// ErrSensitive is an error that occurs when decoding a sensitive value to a Go value.
1918
ErrSensitive = errors.New("")
2019
)

tflint/interface.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,29 @@ type Runner interface {
161161

162162
// EvaluateExpr evaluates the passed expression and reflects the result in the 2nd argument.
163163
// In addition to the obvious errors, this function returns an error if:
164-
// - The expression contains unknown variables (e.g. variables without defaults)
165-
// - The expression contains null variables
166-
// - The expression contains unevaluable references (e.g. `aws_instance.arn`)
164+
// - The expression contains unknown values (e.g. variables without defaults, `aws_instance.foo.arn`)
165+
// - The expression contains null values
166+
// - The expression contains sensitive values (variables with `sensitive = true`)
167167
//
168-
// To ignore these, use EnsureNoError for the returned error:
168+
// You can use `errors.Is` to ignore these errors:
169169
//
170170
// ```
171171
// var val string
172172
// err := runner.EvaluateExpr(expr, &val, nil)
173-
// err = runner.EnsureNoError(err, func () error {
174-
// // Only when no error occurs
175-
// })
176173
// if err != nil {
177-
// // Only for obvious errors, excluding the above errors
174+
// if errors.Is(err, tflint.ErrUnknownValue) {
175+
// // Ignore unknown values
176+
// return nil
177+
// }
178+
// if errors.Is(err, tflint.ErrNullValue) {
179+
// // Ignore null values because null means that the value is not set
180+
// return nil
181+
// }
182+
// if errors.Is(err, tflint.ErrSensitive) {
183+
// // Ignore sensitive values
184+
// return nil
185+
// }
186+
// return err
178187
// }
179188
// ```
180189
//
@@ -211,6 +220,8 @@ type Runner interface {
211220

212221
// EnsureNoError is a helper for error handling. Depending on the type of error generated by EvaluateExpr,
213222
// determine whether to exit, skip, or continue. If it is continued, the passed function will be executed.
223+
//
224+
// Deprecated: Use errors.Is() instead to determine which errors can be ignored.
214225
EnsureNoError(error, func() error) error
215226
}
216227

0 commit comments

Comments
 (0)