Skip to content

Commit e7ddb76

Browse files
authored
Add tflint.ErrSensitive (#174)
1 parent 1e7788c commit e7ddb76

File tree

7 files changed

+104
-79
lines changed

7 files changed

+104
-79
lines changed

plugin/fromproto/fromproto.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ func Error(err error) error {
248248
return fmt.Errorf("%s%w", st.Message(), tflint.ErrNullValue)
249249
case proto.ErrorCode_ERROR_CODE_UNEVALUABLE:
250250
return fmt.Errorf("%s%w", st.Message(), tflint.ErrUnevaluable)
251+
case proto.ErrorCode_ERROR_CODE_SENSITIVE:
252+
return fmt.Errorf("%s%w", st.Message(), tflint.ErrSensitive)
251253
}
252254
}
253255

plugin/plugin2host/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func (*GRPCClient) EnsureNoError(err error, proc func() error) error {
262262
return proc()
263263
}
264264

265-
if errors.Is(err, tflint.ErrUnevaluable) || errors.Is(err, tflint.ErrNullValue) || errors.Is(err, tflint.ErrUnknownValue) {
265+
if errors.Is(err, tflint.ErrUnevaluable) || errors.Is(err, tflint.ErrNullValue) || errors.Is(err, tflint.ErrUnknownValue) || errors.Is(err, tflint.ErrSensitive) {
266266
return nil
267267
}
268268
return err

plugin/plugin2host/plugin2host_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,19 @@ func TestEvaluateExpr(t *testing.T) {
13831383
return !errors.Is(err, tflint.ErrUnevaluable)
13841384
},
13851385
},
1386+
{
1387+
Name: "server returns a sensitive error",
1388+
Expr: hclExpr(`1`),
1389+
TargetType: reflect.TypeOf(0),
1390+
ServerImpl: func(hcl.Expression, tflint.EvaluateExprOption) (cty.Value, error) {
1391+
return cty.Value{}, fmt.Errorf("sensitive%w", tflint.ErrSensitive)
1392+
},
1393+
Want: 0,
1394+
GetFileImpl: fileExists,
1395+
ErrCheck: func(err error) bool {
1396+
return !errors.Is(err, tflint.ErrSensitive)
1397+
},
1398+
},
13861399
}
13871400

13881401
for _, test := range tests {

plugin/proto/tflint.pb.go

Lines changed: 83 additions & 78 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/proto/tflint.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ enum ErrorCode {
231231
ERROR_CODE_UNKNOWN_VALUE = 1;
232232
ERROR_CODE_NULL_VALUE = 2;
233233
ERROR_CODE_UNEVALUABLE = 3;
234+
ERROR_CODE_SENSITIVE = 4;
234235
}
235236

236237
message ErrorDetail {

plugin/toproto/toproto.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ func Error(code codes.Code, err error) error {
186186
errCode = proto.ErrorCode_ERROR_CODE_NULL_VALUE
187187
} else if errors.Is(err, tflint.ErrUnevaluable) {
188188
errCode = proto.ErrorCode_ERROR_CODE_UNEVALUABLE
189+
} else if errors.Is(err, tflint.ErrSensitive) {
190+
errCode = proto.ErrorCode_ERROR_CODE_SENSITIVE
189191
}
190192

191193
if errCode == proto.ErrorCode_ERROR_CODE_UNSPECIFIED {

tflint/errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ var (
1414
ErrNullValue = errors.New("")
1515
// ErrUnevaluable is an error when a received expression has unevaluable references.
1616
ErrUnevaluable = errors.New("")
17+
// ErrSensitive is an error when a received expression contains a sensitive value.
18+
ErrSensitive = errors.New("")
1719
)

0 commit comments

Comments
 (0)