From a56f91b3f74ae382f3249edfacdf4d352331e3ac Mon Sep 17 00:00:00 2001 From: Kazuma Watanabe Date: Sun, 19 Mar 2023 16:14:04 +0000 Subject: [PATCH] Use errors.Is() instead of EnsureNoError --- .../customrulesettesting/custom/runner.go | 26 ++++++++++++------- plugin/stub-generator/sources/example/main.go | 19 +++++++++----- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/plugin/stub-generator/sources/customrulesettesting/custom/runner.go b/plugin/stub-generator/sources/customrulesettesting/custom/runner.go index df00f9150..6bec51777 100644 --- a/plugin/stub-generator/sources/customrulesettesting/custom/runner.go +++ b/plugin/stub-generator/sources/customrulesettesting/custom/runner.go @@ -1,6 +1,8 @@ package custom import ( + "errors" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" ) @@ -51,12 +53,14 @@ func NewRunner(runner tflint.Runner, config *Config) (*Runner, error) { if attr, exists := provider.Body.Attributes["zone"]; exists { var zone string err := runner.EvaluateExpr(attr.Expr, &zone, opts) - err = runner.EnsureNoError(err, func() error { - config.Zone = zone - return nil - }) if err != nil { - return nil, err + if errors.Is(err, tflint.ErrUnknownValue) || errors.Is(err, tflint.ErrNullValue) || errors.Is(err, tflint.ErrSensitive) { + // skip + } else { + return nil, err + } + } else { + config.Zone = zone } } @@ -64,12 +68,14 @@ func NewRunner(runner tflint.Runner, config *Config) (*Runner, error) { if attr, exists := annotation.Body.Attributes["value"]; exists { var val string err := runner.EvaluateExpr(attr.Expr, &val, opts) - err = runner.EnsureNoError(err, func() error { - config.Annotation = val - return nil - }) if err != nil { - return nil, err + if errors.Is(err, tflint.ErrUnknownValue) || errors.Is(err, tflint.ErrNullValue) || errors.Is(err, tflint.ErrSensitive) { + // skip + } else { + return nil, err + } + } else { + config.Annotation = val } } } diff --git a/plugin/stub-generator/sources/example/main.go b/plugin/stub-generator/sources/example/main.go index b02f909e9..e34f5c35c 100644 --- a/plugin/stub-generator/sources/example/main.go +++ b/plugin/stub-generator/sources/example/main.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "github.com/terraform-linters/tflint-plugin-sdk/hclext" @@ -67,14 +68,18 @@ func (r *AwsInstanceExampleTypeRule) Check(runner tflint.Runner) error { var instanceType string err := runner.EvaluateExpr(attribute.Expr, &instanceType, nil) + if err != nil { + if errors.Is(err, tflint.ErrUnknownValue) || errors.Is(err, tflint.ErrNullValue) || errors.Is(err, tflint.ErrSensitive) { + continue + } + return err + } - err = runner.EnsureNoError(err, func() error { - return runner.EmitIssue( - r, - fmt.Sprintf("instance type is %s", instanceType), - attribute.Expr.Range(), - ) - }) + err = runner.EmitIssue( + r, + fmt.Sprintf("instance type is %s", instanceType), + attribute.Expr.Range(), + ) if err != nil { return err }