Skip to content

Commit fd4d361

Browse files
committed
Updated exception messages in BindingModelValidator
Specifically, placed quotes around (most) instance variables, and specified _property_ and _class_ instead of just injecting their names into the error message. E.g., messages now say, "The '{property}' on the '{class}' class…" as opposed to "The {property} on the {class}…".
1 parent 6684b39 commit fd4d361

1 file changed

Lines changed: 33 additions & 29 deletions

File tree

OnTopic/Mapping/BindingModelValidator.cs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ static internal void ValidateProperty(
224224
\-----------------------------------------------------------------------------------------------------------------------*/
225225
if (attributeDescriptor == null) {
226226
throw new InvalidOperationException(
227-
$"A {nameof(sourceType)} object was provided with a content type set to {contentTypeDescriptor.Key}'. This " +
227+
$"A {nameof(sourceType)} object was provided with a content type set to '{contentTypeDescriptor.Key}'. This " +
228228
$"content type does not contain an attribute named '{compositeAttributeKey}', as requested by the " +
229-
$"{configuration.Property.Name} property. If this property is not intended to be mapped by the " +
229+
$"'{configuration.Property.Name}' property. If this property is not intended to be mapped by the " +
230230
$"{nameof(ReverseTopicMappingService)}, then it should be decorated with {nameof(DisableMappingAttribute)}."
231231
);
232232
}
@@ -247,12 +247,12 @@ static internal void ValidateProperty(
247247
listType != null
248248
) {
249249
throw new InvalidOperationException(
250-
$"The {property.Name} on the {sourceType.Name} has been determined to be a {configuration.RelationshipType}, but " +
251-
$"the generic type {listType.Name} does not implement the {nameof(ITopicBindingModel)} interface. This is " +
252-
$"required for binding models. If this collection is not intended to be mapped to " +
253-
$"{ModelType.NestedTopic} then update the definition in the associated {nameof(ContentTypeDescriptor)}. If this " +
254-
$"collection is not intended to be mapped at all, include the {nameof(DisableMappingAttribute)} to exclude it from " +
255-
$"mapping."
250+
$"The '{property.Name}' property on the '{sourceType.Name}' class has been determined to be a " +
251+
$"{configuration.RelationshipType}, but the generic type '{listType.Name}' does not implement the " +
252+
$"{nameof(ITopicBindingModel)} interface. This is required for binding models. If this collection is not intended " +
253+
$"to be mapped as a {ModelType.NestedTopic} then update the definition in the associated " +
254+
$"{nameof(ContentTypeDescriptor)}. If this collection is not intended to be mapped at all, include the " +
255+
$"{nameof(DisableMappingAttribute)} to exclude it from mapping."
256256
);
257257
}
258258

@@ -264,11 +264,12 @@ static internal void ValidateProperty(
264264
!typeof(IRelatedTopicBindingModel).IsAssignableFrom(propertyType)
265265
) {
266266
throw new InvalidOperationException(
267-
$"The {property.Name} on the {sourceType.Name} has been determined to be a {ModelType.Reference}, but " +
268-
$"the generic type {propertyType.Name} does not implement the {nameof(IRelatedTopicBindingModel)} interface. This " +
269-
$"is required for references. If this property is not intended to be mapped to {ModelType.Reference} then update " +
270-
$"the definition in the associated {nameof(ContentTypeDescriptor)}. If this property is not intended to be mapped " +
271-
$"at all, include the {nameof(DisableMappingAttribute)} to exclude it from mapping."
267+
$"The '{property.Name}' property on the '{sourceType.Name}' class has been determined to be a " +
268+
$"{ModelType.Reference}, but the generic type '{propertyType.Name}' does not implement the " +
269+
$"{nameof(IRelatedTopicBindingModel)} interface. This is required for references. If this property is not intended " +
270+
$"to be mapped as a {ModelType.Reference} then update the definition in the associated " +
271+
$"{nameof(ContentTypeDescriptor)}. If this property is not intended to be mapped at all, include the " +
272+
$"{nameof(DisableMappingAttribute)} to exclude it from mapping."
272273
);
273274
}
274275

@@ -280,12 +281,13 @@ static internal void ValidateProperty(
280281
!configuration.AttributeKey.EndsWith("Id", StringComparison.InvariantCulture)
281282
) {
282283
throw new InvalidOperationException(
283-
$"The {property.Name} on the {sourceType.Name} has been determined to be a topic reference, but the generic type " +
284-
$"{compositeAttributeKey} does not end in <c>Id</c>. By convention, all topic reference are expected to end " +
285-
$"in <c>Id</c>. To keep the property name set to {propertyType.Name}, use the {nameof(AttributeKeyAttribute)} to " +
286-
$"specify the name of the topic reference this should map to. If this property is not intended to be mapped at " +
287-
$"all, include the {nameof(DisableMappingAttribute)}. If the {contentTypeDescriptor.Key} defines a topic reference " +
288-
$"attribute that doesn't follow this convention, then it should be updated."
284+
$"The '{property.Name}' property on the '{sourceType.Name}' class has been determined to be a topic reference, but " +
285+
$"the generic type '{compositeAttributeKey}' does not end in <c>Id</c>. By convention, all topic reference are " +
286+
$"expected to end in <c>Id</c>. To keep the property name set to '{propertyType.Name}', use the " +
287+
$"{nameof(AttributeKeyAttribute)} to specify the name of the topic reference this should map to. If this property " +
288+
$"is not intended to be mapped at all, include the {nameof(DisableMappingAttribute)}. If the " +
289+
$"'{contentTypeDescriptor.Key}' defines a topic reference attribute that doesn't follow this convention, then it " +
290+
$"should be updated."
289291
);
290292
}
291293

@@ -333,8 +335,9 @@ [AllowNull]Type listType
333335
\-----------------------------------------------------------------------------------------------------------------------*/
334336
if (!typeof(IList).IsAssignableFrom(property.PropertyType)) {
335337
throw new InvalidOperationException(
336-
$"The {property.Name} on the {sourceType.Name} maps to a relationship attribute {attributeDescriptor.Key}, but does" +
337-
$"not implement {nameof(IList)}. Relationships must implement {nameof(IList)} or derive from a collection that does."
338+
$"The '{property.Name}' property on the '{sourceType.Name}' class maps to a relationship attribute " +
339+
$"'{attributeDescriptor.Key}', but does not implement {nameof(IList)}. Relationships must implement " +
340+
$"{nameof(IList)} or derive from a collection that does."
338341
);
339342
}
340343

@@ -343,9 +346,9 @@ [AllowNull]Type listType
343346
\-----------------------------------------------------------------------------------------------------------------------*/
344347
if (!new[] { RelationshipType.Any, RelationshipType.Relationship }.Contains(configuration.RelationshipType)) {
345348
throw new InvalidOperationException(
346-
$"The {property.Name} on the {sourceType.Name} maps to a relationship attribute {attributeDescriptor.Key}, but is " +
347-
$"configured as a {configuration.RelationshipType}. The property should be flagged as either " +
348-
$"{nameof(RelationshipType.Any)} or {nameof(RelationshipType.Relationship)}."
349+
$"The '{property.Name}' property on the '{sourceType.Name}' class maps to a relationship attribute " +
350+
$"'{attributeDescriptor.Key}', but is configured as a {configuration.RelationshipType}. The property should be " +
351+
$"flagged as either {nameof(RelationshipType.Any)} or {nameof(RelationshipType.Relationship)}."
349352
);
350353
}
351354

@@ -354,11 +357,12 @@ [AllowNull]Type listType
354357
\-----------------------------------------------------------------------------------------------------------------------*/
355358
if (!typeof(IRelatedTopicBindingModel).IsAssignableFrom(listType)) {
356359
throw new InvalidOperationException(
357-
$"The {property.Name} on the {sourceType.Name} has been determined to be a {configuration.RelationshipType}, but " +
358-
$"the generic type {listType.Name} does not implement the {nameof(IRelatedTopicBindingModel)} interface. This is " +
359-
$"required for binding models. If this collection is not intended to be mapped to {configuration.RelationshipType} " +
360-
$"then update the definition in the associated {nameof(ContentTypeDescriptor)}. If this collection is not intended " +
361-
$"to be mapped at all, include the {nameof(DisableMappingAttribute)} to exclude it from mapping."
360+
$"The '{property.Name}' property on the '{sourceType.Name}' class has been determined to be a " +
361+
$"{configuration.RelationshipType}, but the generic type '{listType?.Name}' does not implement the " +
362+
$"{nameof(IRelatedTopicBindingModel)} interface. This is required for binding models. If this collection is not " +
363+
$"intended to be mapped as a {configuration.RelationshipType} then update the definition in the associated " +
364+
$"{nameof(ContentTypeDescriptor)}. If this collection is not intended to be mapped at all, include the " +
365+
$"{nameof(DisableMappingAttribute)} to exclude it from mapping."
362366
);
363367
}
364368

0 commit comments

Comments
 (0)