Skip to content

Commit 71b0b09

Browse files
committed
Updated AttributeInvalidElementTypeDiag with a more descriptive error message
1 parent 49ed817 commit 71b0b09

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

internal/fwschema/diagnostics.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,15 @@ func AttributeDefaultTypeMismatchDiag(attributePath path.Path, expectedType attr
6868
// AttributeInvalidElementTypeDiag returns an error diagnostic to provider
6969
// developers about using non-primitive types in their Attribute
7070
// implementation. This is not allowed.
71-
func AttributeInvalidElementTypeDiag(attributePath path.Path) diag.Diagnostic {
71+
func AttributeInvalidElementTypeDiag(attributePath path.Path, actualType attr.Type) diag.Diagnostic {
7272
// The diagnostic path is intentionally omitted as it is invalid in this
7373
// context. Diagnostic paths are intended to be mapped to actual data,
7474
// while this path information must be synthesized.
7575
return diag.NewErrorDiagnostic(
7676
"Invalid Attribute Implementation",
7777
"When validating the schema, an implementation issue was found. "+
7878
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
79-
fmt.Sprintf("%q contains an Attribute type that is not allowed for Resource Identity. ", attributePath),
79+
fmt.Sprintf("%q contains an Attribute of type %q that is not allowed for Lists in Resource Identity. ", attributePath, actualType)+
80+
"Lists in Resource Identity may only have primitive element types such as Bool, Int, Float, Number and String.",
8081
)
8182
}

resource/identityschema/list_attribute.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,6 @@ func (a ListAttribute) ValidateImplementation(_ context.Context, req fwschema.Va
168168
}
169169

170170
if a.CustomType == nil && !fwtype.IsAllowedPrimitiveType(a.ElementType) {
171-
resp.Diagnostics.Append(fwschema.AttributeInvalidElementTypeDiag(req.Path))
171+
resp.Diagnostics.Append(fwschema.AttributeInvalidElementTypeDiag(req.Path, a.ElementType))
172172
}
173173
}

resource/identityschema/list_attribute_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,8 @@ func TestListAttributeValidateImplementation(t *testing.T) {
561561
"Invalid Attribute Implementation",
562562
"When validating the schema, an implementation issue was found. "+
563563
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
564-
"\"test\" contains an Attribute type that is not allowed for Resource Identity. ",
564+
"\"test\" contains an Attribute of type \"basetypes.DynamicType\" that is not allowed for Lists in Resource Identity. "+
565+
"Lists in Resource Identity may only have primitive element types such as Bool, Int, Float, Number and String.",
565566
),
566567
},
567568
},
@@ -581,7 +582,8 @@ func TestListAttributeValidateImplementation(t *testing.T) {
581582
"Invalid Attribute Implementation",
582583
"When validating the schema, an implementation issue was found. "+
583584
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
584-
"\"test\" contains an Attribute type that is not allowed for Resource Identity. ",
585+
"\"test\" contains an Attribute of type \"types.ObjectType[]\" that is not allowed for Lists in Resource Identity. "+
586+
"Lists in Resource Identity may only have primitive element types such as Bool, Int, Float, Number and String.",
585587
),
586588
},
587589
},
@@ -601,7 +603,8 @@ func TestListAttributeValidateImplementation(t *testing.T) {
601603
"Invalid Attribute Implementation",
602604
"When validating the schema, an implementation issue was found. "+
603605
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
604-
"\"test\" contains an Attribute type that is not allowed for Resource Identity. ",
606+
"\"test\" contains an Attribute of type \"types.MapType[!!! MISSING TYPE !!!]\" that is not allowed for Lists in Resource Identity. "+
607+
"Lists in Resource Identity may only have primitive element types such as Bool, Int, Float, Number and String.",
605608
),
606609
},
607610
},

0 commit comments

Comments
 (0)