diff --git a/helper/runner.go b/helper/runner.go index 3362f87..300310f 100644 --- a/helper/runner.go +++ b/helper/runner.go @@ -265,6 +265,8 @@ func (r *Runner) EmitIssue(rule tflint.Rule, message string, location hcl.Range) } // EnsureNoError is a method that simply runs a function if there is no error. +// +// Deprecated: Use errors.Is() instead to determine which errors can be ignored. func (r *Runner) EnsureNoError(err error, proc func() error) error { if err == nil { return proc() diff --git a/plugin/plugin2host/client.go b/plugin/plugin2host/client.go index 122cf0c..168da45 100644 --- a/plugin/plugin2host/client.go +++ b/plugin/plugin2host/client.go @@ -367,6 +367,8 @@ func (c *GRPCClient) EmitIssue(rule tflint.Rule, message string, location hcl.Ra // EnsureNoError is a helper for error handling. Depending on the type of error generated by EvaluateExpr, // determine whether to exit, skip, or continue. If it is continued, the passed function will be executed. +// +// Deprecated: Use errors.Is() instead to determine which errors can be ignored. func (*GRPCClient) EnsureNoError(err error, proc func() error) error { if err == nil { return proc() diff --git a/tflint/errors.go b/tflint/errors.go index de6a2e9..027cefa 100644 --- a/tflint/errors.go +++ b/tflint/errors.go @@ -5,16 +5,15 @@ import ( ) // List of errors returned by TFLint. -// It's possible to get this error from a plugin, but the error handling is hidden -// inside the plugin system, so you usually don't have to worry about it. var ( - // ErrUnknownValue is an error when an unknown value is referenced + // ErrUnknownValue is an error that occurs when decoding an unknown value to a Go value. ErrUnknownValue = errors.New("unknown value found") - // ErrNullValue is an error when null value is referenced + // ErrNullValue is an error that occurs when decoding null to a Go value. ErrNullValue = errors.New("null value found") - // ErrUnevaluable is an error when a received expression has unevaluable references. + // ErrUnevaluable is an error that occurs when decoding an unevaluable value to a Go value. + // // Deprecated: This error is no longer returned since TFLint v0.41. ErrUnevaluable = errors.New("") - // ErrSensitive is an error when a received expression contains a sensitive value. + // ErrSensitive is an error that occurs when decoding a sensitive value to a Go value. ErrSensitive = errors.New("") ) diff --git a/tflint/interface.go b/tflint/interface.go index 2a7a617..b82a780 100644 --- a/tflint/interface.go +++ b/tflint/interface.go @@ -161,20 +161,29 @@ type Runner interface { // EvaluateExpr evaluates the passed expression and reflects the result in the 2nd argument. // In addition to the obvious errors, this function returns an error if: - // - The expression contains unknown variables (e.g. variables without defaults) - // - The expression contains null variables - // - The expression contains unevaluable references (e.g. `aws_instance.arn`) + // - The expression contains unknown values (e.g. variables without defaults, `aws_instance.foo.arn`) + // - The expression contains null values + // - The expression contains sensitive values (variables with `sensitive = true`) // - // To ignore these, use EnsureNoError for the returned error: + // You can use `errors.Is` to ignore these errors: // // ``` // var val string // err := runner.EvaluateExpr(expr, &val, nil) - // err = runner.EnsureNoError(err, func () error { - // // Only when no error occurs - // }) // if err != nil { - // // Only for obvious errors, excluding the above errors + // if errors.Is(err, tflint.ErrUnknownValue) { + // // Ignore unknown values + // return nil + // } + // if errors.Is(err, tflint.ErrNullValue) { + // // Ignore null values because null means that the value is not set + // return nil + // } + // if errors.Is(err, tflint.ErrSensitive) { + // // Ignore sensitive values + // return nil + // } + // return err // } // ``` // @@ -211,6 +220,8 @@ type Runner interface { // EnsureNoError is a helper for error handling. Depending on the type of error generated by EvaluateExpr, // determine whether to exit, skip, or continue. If it is continued, the passed function will be executed. + // + // Deprecated: Use errors.Is() instead to determine which errors can be ignored. EnsureNoError(error, func() error) error }