Skip to content

all: Included missing attribute path details in error diagnostics #61

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

Merged
merged 3 commits into from
Aug 30, 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
3 changes: 3 additions & 0 deletions .changelog/61.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
all: Included missing attribute path details in error diagnostics since they are currently not output by Terraform
```
2 changes: 1 addition & 1 deletion float64validator/type_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func validateFloat(ctx context.Context, request tfsdk.ValidateAttributeRequest,
if t != types.Float64Type {
response.Diagnostics.Append(validatordiag.InvalidAttributeTypeDiagnostic(
request.AttributePath,
"Expected value of type float64",
"expected value of type float64",
t.String(),
))
return 0.0, false
Expand Down
9 changes: 5 additions & 4 deletions helpers/validatordiag/diag.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package validatordiag

import (
"fmt"
"unicode"
"unicode/utf8"

Expand All @@ -13,7 +14,7 @@ func InvalidAttributeValueDiagnostic(path path.Path, description string, value s
return diag.NewAttributeErrorDiagnostic(
path,
"Invalid Attribute Value",
capitalize(description)+", got: "+value,
fmt.Sprintf("Attribute %s %s, got: %s", path, description, value),
)
}

Expand All @@ -22,7 +23,7 @@ func InvalidAttributeValueLengthDiagnostic(path path.Path, description string, v
return diag.NewAttributeErrorDiagnostic(
path,
"Invalid Attribute Value Length",
capitalize(description)+", got: "+value,
fmt.Sprintf("Attribute %s %s, got: %s", path, description, value),
)
}

Expand All @@ -31,7 +32,7 @@ func InvalidAttributeValueMatchDiagnostic(path path.Path, description string, va
return diag.NewAttributeErrorDiagnostic(
path,
"Invalid Attribute Value Match",
capitalize(description)+", got: "+value,
fmt.Sprintf("Attribute %s %s, got: %s", path, description, value),
)
}

Expand All @@ -49,7 +50,7 @@ func InvalidAttributeTypeDiagnostic(path path.Path, description string, value st
return diag.NewAttributeErrorDiagnostic(
path,
"Invalid Attribute Type",
capitalize(description)+", got: "+value,
fmt.Sprintf("Attribute %s %s, got: %s", path, description, value),
)
}

Expand Down
4 changes: 2 additions & 2 deletions metavalidator/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestAllValidator(t *testing.T) {
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Type",
"Expected value of type string, got: types.Int64Type",
"Attribute test expected value of type string, got: types.Int64Type",
),
},
},
Expand All @@ -51,7 +51,7 @@ func TestAllValidator(t *testing.T) {
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value Length",
"String length must be at least 5, got: 3",
"Attribute test string length must be at least 5, got: 3",
),
},
},
Expand Down
10 changes: 5 additions & 5 deletions metavalidator/any_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestAnyValidator(t *testing.T) {
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Type",
"Expected value of type string, got: types.Int64Type",
"Attribute test expected value of type string, got: types.Int64Type",
),
},
},
Expand All @@ -51,12 +51,12 @@ func TestAnyValidator(t *testing.T) {
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value Length",
"String length must be at least 4, got: 3",
"Attribute test string length must be at least 4, got: 3",
),
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value Length",
"String length must be at least 5, got: 3",
"Attribute test string length must be at least 5, got: 3",
),
},
},
Expand All @@ -80,12 +80,12 @@ func TestAnyValidator(t *testing.T) {
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value Length",
"String length must be at least 6, got: 3",
"Attribute test string length must be at least 6, got: 3",
),
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value Length",
"String length must be at least 5, got: 3",
"Attribute test string length must be at least 5, got: 3",
),
},
},
Expand Down
10 changes: 5 additions & 5 deletions metavalidator/any_with_all_warnings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestAnyWithAllWarningsValidator(t *testing.T) {
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Type",
"Expected value of type string, got: types.Int64Type",
"Attribute test expected value of type string, got: types.Int64Type",
),
},
},
Expand All @@ -70,12 +70,12 @@ func TestAnyWithAllWarningsValidator(t *testing.T) {
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value Length",
"String length must be at least 4, got: 3",
"Attribute test string length must be at least 4, got: 3",
),
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value Length",
"String length must be at least 5, got: 3",
"Attribute test string length must be at least 5, got: 3",
),
},
},
Expand All @@ -99,12 +99,12 @@ func TestAnyWithAllWarningsValidator(t *testing.T) {
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value Length",
"String length must be at least 6, got: 3",
"Attribute test string length must be at least 6, got: 3",
),
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value Length",
"String length must be at least 5, got: 3",
"Attribute test string length must be at least 5, got: 3",
),
},
},
Expand Down
2 changes: 1 addition & 1 deletion stringvalidator/type_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func validateString(ctx context.Context, request tfsdk.ValidateAttributeRequest,
if t != types.StringType {
response.Diagnostics.Append(validatordiag.InvalidAttributeTypeDiagnostic(
request.AttributePath,
"Expected value of type string",
"expected value of type string",
t.String(),
))
return "", false
Expand Down