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

Improve exception messages (cont...) #22450

Merged
1 commit merged into from
Sep 8, 2020
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: 1 addition & 1 deletion src/EFCore/Infrastructure/Annotatable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected virtual Annotation AddAnnotation([NotNull] string name, [NotNull] Anno
{
if (FindAnnotation(name) != null)
{
throw new InvalidOperationException(CoreStrings.DuplicateAnnotation(name));
throw new InvalidOperationException(CoreStrings.DuplicateAnnotation(name, ToString()));
}

SetAnnotation(name, annotation, oldAnnotation: null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ var fkPropertiesOnDependentToPrincipal
throw new InvalidOperationException(
CoreStrings.ConflictingForeignKeyAttributes(
existingProperties.Format(),
foreignKey.DeclaringEntityType.DisplayName()));
foreignKey.DeclaringEntityType.DisplayName(),
foreignKey.PrincipalEntityType.DisplayName()));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/Metadata/Internal/EntityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ public virtual Key AddKey(
{
if (property == properties[j])
{
throw new InvalidOperationException(CoreStrings.DuplicatePropertyInList(properties.Format(), property.Name));
throw new InvalidOperationException(CoreStrings.DuplicatePropertyInKey(properties.Format(), property.Name));
}
}

Expand Down Expand Up @@ -2059,7 +2059,7 @@ private void CheckIndexProperties(IReadOnlyList<Property> properties)
{
if (property == properties[j])
{
throw new InvalidOperationException(CoreStrings.DuplicatePropertyInList(properties.Format(), property.Name));
throw new InvalidOperationException(CoreStrings.DuplicatePropertyInIndex(properties.Format(), property.Name));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Internal/ForeignKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ private void Validate(
{
if (property == properties[j])
{
throw new InvalidOperationException(CoreStrings.DuplicatePropertyInList(properties.Format(), property.Name));
throw new InvalidOperationException(CoreStrings.DuplicatePropertyInForeignKey(properties.Format(), property.Name));
}
}

Expand Down
40 changes: 28 additions & 12 deletions src/EFCore/Properties/CoreStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions src/EFCore/Properties/CoreStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
<value>Property '{1_entityType}.{0_property}' matches both '{field1}' and '{field2}' by convention. Explicitly specify the backing field to use with 'HasField' in 'OnModelCreating'.</value>
</data>
<data name="ConflictingForeignKeyAttributes" xml:space="preserve">
<value>There are multiple [ForeignKey] attributes which are pointing to same set of properties '{propertyList}' on entity type '{entityType}'.</value>
<value>There are multiple [ForeignKey] attributes which are pointing to same set of properties '{propertyList}' on entity type '{entityType}' and targeting the principal entity type '{principalEntityType}'.</value>
</data>
<data name="ConflictingPropertyOrNavigation" xml:space="preserve">
<value>The property or navigation '{member}' cannot be added to the entity type '{entityType}' because a property or navigation with the same name already exists on entity type '{conflictingEntityType}'.</value>
Expand Down Expand Up @@ -346,7 +346,7 @@
<value>Cannot set discriminator value '{value}' for discriminator property '{discriminator}' because it is not assignable to type '{discriminatorType}'.</value>
</data>
<data name="DuplicateAnnotation" xml:space="preserve">
<value>The annotation '{annotation}' cannot be added because an annotation with the same name already exists.</value>
<value>The annotation '{annotation}' cannot be added because an annotation with the same name already exists on the object {annotatable}</value>
</data>
<data name="DuplicateDiscriminatorValue" xml:space="preserve">
<value>The discriminator value for '{entityType1}' is '{discriminatorValue}' which is the same for '{entityType2}'. Every concrete entity type in the hierarchy must have a unique discriminator value.</value>
Expand All @@ -369,8 +369,14 @@
<data name="DuplicatePropertiesOnBase" xml:space="preserve">
<value>The type '{entityType}' cannot have base type '{baseType}' because the properties '{derivedPropertyType}.{derivedProperty}' and '{basePropertyType}.{baseProperty}' are conflicting.</value>
</data>
<data name="DuplicatePropertyInList" xml:space="preserve">
<value>The properties {propertyList} cannot be used, because they contain a duplicate: '{property}'.</value>
<data name="DuplicatePropertyInForeignKey" xml:space="preserve">
<value>The properties {propertyList} cannot be used for a foreign key, because they contain a duplicate: '{property}'.</value>
</data>
<data name="DuplicatePropertyInIndex" xml:space="preserve">
<value>The properties {propertyList} cannot be used for an index, because they contain a duplicate: '{property}'.</value>
</data>
<data name="DuplicatePropertyInKey" xml:space="preserve">
<value>The properties {propertyList} cannot be used for a key, because they contain a duplicate: '{property}'.</value>
</data>
<data name="DuplicateServicePropertyType" xml:space="preserve">
<value>The service property '{property}' of type '{serviceType}' cannot be added to the entity type '{entityType}' because service property '{duplicateName}' of the same type already exists on entity type '{duplicateEntityType}'.</value>
Expand Down Expand Up @@ -1143,7 +1149,7 @@
<value>The owned entity type '{ownedType}' must be referenced from another entity type via a navigation. Add a navigation to an entity type that points at '{ownedType}'.</value>
</data>
<data name="PoolingContextCtorError" xml:space="preserve">
<value>The DbContext of type '{contextType}' cannot be pooled because it does not have a single public constructor accepting a single parameter of type DbContextOptions.</value>
<value>The DbContext of type '{contextType}' cannot be pooled because it does not have a public constructor accepting a single parameter of type DbContextOptions or has more than one constructor.</value>
</data>
<data name="PoolingOptionsModified" xml:space="preserve">
<value>'OnConfiguring' cannot be used to modify DbContextOptions when DbContext pooling is enabled.</value>
Expand Down
2 changes: 1 addition & 1 deletion test/EFCore.Specification.Tests/DataAnnotationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2175,7 +2175,7 @@ public virtual void ForeignKeyAttribute_throws_if_applied_on_two_relationships_t
modelBuilder.Ignore<B>();

Assert.Equal(
CoreStrings.ConflictingForeignKeyAttributes("{'AId'}", nameof(ConflictingFKAttributes)),
CoreStrings.ConflictingForeignKeyAttributes("{'AId'}", nameof(ConflictingFKAttributes), nameof(A)),
Assert.Throws<InvalidOperationException>(() => modelBuilder.Entity<ConflictingFKAttributes>()).Message);
}

Expand Down
2 changes: 1 addition & 1 deletion test/EFCore.Tests/Infrastructure/AnnotatableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void Addind_duplicate_annotation_throws()
annotatable.AddAnnotation("Foo", "Bar");

Assert.Equal(
CoreStrings.DuplicateAnnotation("Foo"),
CoreStrings.DuplicateAnnotation("Foo", annotatable.ToString()),
Assert.Throws<InvalidOperationException>(() => annotatable.AddAnnotation("Foo", "Bar")).Message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ public void Adding_an_index_throws_if_duplicate_properties()
var idProperty = entityType.AddProperty(Customer.IdProperty);

Assert.Equal(
CoreStrings.DuplicatePropertyInList(
CoreStrings.DuplicatePropertyInIndex(
"{'" + Customer.IdProperty.Name + "', '" + Customer.IdProperty.Name + "'}", Customer.IdProperty.Name),
Assert.Throws<InvalidOperationException>(() => entityType.AddIndex(new[] { idProperty, idProperty })).Message);
}
Expand Down
4 changes: 2 additions & 2 deletions test/EFCore.Tests/Metadata/Internal/EntityTypeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public void Adding_a_key_throws_if_duplicated_properties()
var idProperty = entityType.AddProperty(Customer.IdProperty);

Assert.Equal(
CoreStrings.DuplicatePropertyInList(
CoreStrings.DuplicatePropertyInKey(
"{'" + Customer.IdProperty.Name + "', '" + Customer.IdProperty.Name + "'}", Customer.IdProperty.Name),
Assert.Throws<InvalidOperationException>(() => entityType.AddKey(new[] { idProperty, idProperty })).Message);
}
Expand Down Expand Up @@ -632,7 +632,7 @@ public void Adding_a_foreign_key_throws_if_duplicated_properties()
var customerFk1 = orderType.AddProperty(Order.CustomerIdProperty);

Assert.Equal(
CoreStrings.DuplicatePropertyInList(
CoreStrings.DuplicatePropertyInForeignKey(
"{'" + Order.CustomerIdProperty.Name + "', '" + Order.CustomerIdProperty.Name + "'}",
Order.CustomerIdProperty.Name),
Assert.Throws<InvalidOperationException>(
Expand Down