Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tflint.ErrSensitive #174

Merged
merged 1 commit into from
Jul 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("")
)