Skip to content

Commit

Permalink
Add tflint.ErrSensitive (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 authored Jul 31, 2022
1 parent 1e7788c commit e7ddb76
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 79 deletions.
2 changes: 2 additions & 0 deletions plugin/fromproto/fromproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ func Error(err error) error {
return fmt.Errorf("%s%w", st.Message(), tflint.ErrNullValue)
case proto.ErrorCode_ERROR_CODE_UNEVALUABLE:
return fmt.Errorf("%s%w", st.Message(), tflint.ErrUnevaluable)
case proto.ErrorCode_ERROR_CODE_SENSITIVE:
return fmt.Errorf("%s%w", st.Message(), tflint.ErrSensitive)
}
}

Expand Down
2 changes: 1 addition & 1 deletion plugin/plugin2host/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (*GRPCClient) EnsureNoError(err error, proc func() error) error {
return proc()
}

if errors.Is(err, tflint.ErrUnevaluable) || errors.Is(err, tflint.ErrNullValue) || errors.Is(err, tflint.ErrUnknownValue) {
if errors.Is(err, tflint.ErrUnevaluable) || errors.Is(err, tflint.ErrNullValue) || errors.Is(err, tflint.ErrUnknownValue) || errors.Is(err, tflint.ErrSensitive) {
return nil
}
return err
Expand Down
13 changes: 13 additions & 0 deletions plugin/plugin2host/plugin2host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,19 @@ func TestEvaluateExpr(t *testing.T) {
return !errors.Is(err, tflint.ErrUnevaluable)
},
},
{
Name: "server returns a sensitive error",
Expr: hclExpr(`1`),
TargetType: reflect.TypeOf(0),
ServerImpl: func(hcl.Expression, tflint.EvaluateExprOption) (cty.Value, error) {
return cty.Value{}, fmt.Errorf("sensitive%w", tflint.ErrSensitive)
},
Want: 0,
GetFileImpl: fileExists,
ErrCheck: func(err error) bool {
return !errors.Is(err, tflint.ErrSensitive)
},
},
}

for _, test := range tests {
Expand Down
161 changes: 83 additions & 78 deletions plugin/proto/tflint.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions plugin/proto/tflint.proto
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ enum ErrorCode {
ERROR_CODE_UNKNOWN_VALUE = 1;
ERROR_CODE_NULL_VALUE = 2;
ERROR_CODE_UNEVALUABLE = 3;
ERROR_CODE_SENSITIVE = 4;
}

message ErrorDetail {
Expand Down
2 changes: 2 additions & 0 deletions plugin/toproto/toproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ func Error(code codes.Code, err error) error {
errCode = proto.ErrorCode_ERROR_CODE_NULL_VALUE
} else if errors.Is(err, tflint.ErrUnevaluable) {
errCode = proto.ErrorCode_ERROR_CODE_UNEVALUABLE
} else if errors.Is(err, tflint.ErrSensitive) {
errCode = proto.ErrorCode_ERROR_CODE_SENSITIVE
}

if errCode == proto.ErrorCode_ERROR_CODE_UNSPECIFIED {
Expand Down
2 changes: 2 additions & 0 deletions tflint/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ var (
ErrNullValue = errors.New("")
// ErrUnevaluable is an error when a received expression has unevaluable references.
ErrUnevaluable = errors.New("")
// ErrSensitive is an error when a received expression contains a sensitive value.
ErrSensitive = errors.New("")
)

0 comments on commit e7ddb76

Please sign in to comment.