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

Move exception messages #22108

Merged
1 commit merged into from
Aug 18, 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
28 changes: 28 additions & 0 deletions src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs

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

12 changes: 12 additions & 0 deletions src/EFCore.Cosmos/Properties/CosmosStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,16 @@
<data name="MissingOrderingInSqlExpression" xml:space="preserve">
<value>Reverse could not be translated to the server because there is no ordering on the server side.</value>
</data>
<data name="NullTypeMappingInSqlTree" xml:space="preserve">
<value>Null TypeMapping in Sql Tree.</value>
</data>
<data name="UnableToBindMemberToEntityProjection" xml:space="preserve">
<value>Unable to bind '{memberType}' '{member}' to entity projection of '{entityType}'.</value>
</data>
<data name="UnsupportedOperatorForSqlExpression" xml:space="preserve">
<value>Unsupported operator '{nodeType}' specified for expression of type '{expressionType}'.</value>
</data>
<data name="VisitChildrenMustBeOverridden" xml:space="preserve">
<value>VisitChildren must be overridden in class deriving from SqlExpression.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ private ShapedQueryExpression AggregateResultShaper(
Expression.New(
typeof(InvalidOperationException).GetConstructors()
.Single(ci => ci.GetParameters().Length == 1),
Expression.Constant(CoreStrings.NoElements)),
Expression.Constant(CoreStrings.SequenceContainsNoElements)),
resultType);

shaper = Expression.Block(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Linq.Expressions;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
Expand Down Expand Up @@ -963,7 +964,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
if (extensionExpression is SqlExpression sqlExpression
&& sqlExpression.TypeMapping == null)
{
throw new InvalidOperationException(CoreStrings.NullTypeMappingInSqlTree);
throw new InvalidOperationException(CosmosStrings.NullTypeMappingInSqlTree);
}

return base.VisitExtension(extensionExpression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ public virtual Expression BindProperty([NotNull] IProperty property, bool client
&& !property.DeclaringEntityType.IsAssignableFrom(EntityType))
{
throw new InvalidOperationException(
CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface(
"GetProperty", nameof(IProperty), EntityType.DisplayName(), $"Property:{property.Name}"));
CosmosStrings.UnableToBindMemberToEntityProjection("Property", property.Name, EntityType.DisplayName()));
}

if (!_propertyExpressionsMap.TryGetValue(property, out var expression))
Expand Down Expand Up @@ -150,8 +149,7 @@ public virtual Expression BindNavigation([NotNull] INavigation navigation, bool
&& !navigation.DeclaringEntityType.IsAssignableFrom(EntityType))
{
throw new InvalidOperationException(
CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface(
"GetNavigation", nameof(INavigation), EntityType.DisplayName(), $"Navigation:{navigation.Name}"));
CosmosStrings.UnableToBindMemberToEntityProjection("Navigation", navigation.Name, EntityType.DisplayName()));
}

if (!_navigationExpressionsMap.TryGetValue(navigation, out var expression))
Expand Down
5 changes: 4 additions & 1 deletion src/EFCore.Cosmos/Query/Internal/SqlBinaryExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
Expand Down Expand Up @@ -45,7 +47,8 @@ public class SqlBinaryExpression : SqlExpression
private static ExpressionType VerifyOperator(ExpressionType operatorType)
=> _allowedOperators.Contains(operatorType)
? operatorType
: throw new InvalidOperationException(CoreStrings.UnsupportedBinaryOperator);
: throw new InvalidOperationException(CosmosStrings.UnsupportedOperatorForSqlExpression(
operatorType, typeof(SqlBinaryExpression).ShortDisplayName()));

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore.Cosmos/Query/Internal/SqlExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
Expand Down Expand Up @@ -53,7 +54,7 @@ protected SqlExpression([NotNull] Type type, [CanBeNull] CoreTypeMapping typeMap
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override Expression VisitChildren(ExpressionVisitor visitor)
=> throw new InvalidOperationException(CoreStrings.VisitChildrenMustBeOverridden);
=> throw new InvalidOperationException(CosmosStrings.VisitChildrenMustBeOverridden);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
7 changes: 5 additions & 2 deletions src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
Expand Down Expand Up @@ -137,7 +138,8 @@ when sqlUnaryExpression.IsLogicalNot():
break;

default:
throw new InvalidOperationException(CoreStrings.TranslationFailed(sqlUnaryExpression.Print()));
throw new InvalidOperationException(CosmosStrings.UnsupportedOperatorForSqlExpression(
sqlUnaryExpression.OperatorType, typeof(SqlUnaryExpression).ShortDisplayName()));;
}

return new SqlUnaryExpression(sqlUnaryExpression.OperatorType, operand, resultType, resultTypeMapping);
Expand Down Expand Up @@ -197,7 +199,8 @@ private SqlExpression ApplyTypeMappingOnSqlBinary(
break;

default:
throw new InvalidOperationException(CoreStrings.IncorrectOperatorType);
throw new InvalidOperationException(CosmosStrings.UnsupportedOperatorForSqlExpression(
sqlBinaryExpression.OperatorType, typeof(SqlBinaryExpression).ShortDisplayName()));
}

return new SqlBinaryExpression(
Expand Down
5 changes: 4 additions & 1 deletion src/EFCore.Cosmos/Query/Internal/SqlUnaryExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
Expand All @@ -28,7 +30,8 @@ public class SqlUnaryExpression : SqlExpression
private static ExpressionType VerifyOperator(ExpressionType operatorType)
=> _allowedOperators.Contains(operatorType)
? operatorType
: throw new InvalidOperationException(CoreStrings.UnsupportedUnary);
: throw new InvalidOperationException(CosmosStrings.UnsupportedOperatorForSqlExpression(
operatorType, typeof(SqlUnaryExpression).ShortDisplayName()));

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
8 changes: 8 additions & 0 deletions src/EFCore.InMemory/Properties/InMemoryStrings.Designer.cs

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

3 changes: 3 additions & 0 deletions src/EFCore.InMemory/Properties/InMemoryStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,7 @@
<data name="InvalidDerivedTypeInEntityProjection" xml:space="preserve">
<value>'UpdateEntityType' called with '{derivedType}' which is not derived type of '{entityType}'.</value>
</data>
<data name="UnableToBindMemberToEntityProjection" xml:space="preserve">
<value>Unable to bind '{memberType}' '{member}' to entity projection of '{entityType}'.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ public virtual Expression BindProperty([NotNull] IProperty property)
&& !property.DeclaringEntityType.IsAssignableFrom(EntityType))
{
throw new InvalidOperationException(
CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface(
"BindProperty", nameof(IProperty), EntityType.DisplayName(), $"Property:{property.Name}"));
InMemoryStrings.UnableToBindMemberToEntityProjection("Property", property.Name, EntityType.DisplayName()));
}

return _readExpressionMap[property];
Expand All @@ -121,8 +120,7 @@ public virtual void AddNavigationBinding([NotNull] INavigation navigation, [NotN
&& !navigation.DeclaringEntityType.IsAssignableFrom(EntityType))
{
throw new InvalidOperationException(
CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface(
"AddNavigationBinding", nameof(INavigation), EntityType.DisplayName(), $"Property:{navigation.Name}"));
InMemoryStrings.UnableToBindMemberToEntityProjection("Navigation", navigation.Name, EntityType.DisplayName()));
}

_navigationExpressionsCache[navigation] = entityShaper;
Expand All @@ -140,8 +138,7 @@ public virtual EntityShaperExpression BindNavigation([NotNull] INavigation navig
&& !navigation.DeclaringEntityType.IsAssignableFrom(EntityType))
{
throw new InvalidOperationException(
CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface(
"BindNavigation", nameof(INavigation), EntityType.DisplayName(), $"Property:{navigation.Name}"));
InMemoryStrings.UnableToBindMemberToEntityProjection("Navigation", navigation.Name, EntityType.DisplayName()));
}

return _navigationExpressionsCache.TryGetValue(navigation, out var expression)
Expand Down
36 changes: 36 additions & 0 deletions src/EFCore.Relational/Properties/RelationalStrings.Designer.cs

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

15 changes: 15 additions & 0 deletions src/EFCore.Relational/Properties/RelationalStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -747,4 +747,19 @@
<data name="TableNotMappedEntityType" xml:space="preserve">
<value>The entity type '{entityType}' is not mapped to the store object '{table}'.</value>
</data>
<data name="LastUsedWithoutOrderBy" xml:space="preserve">
<value>Queries performing '{method}' operation must have a deterministic sort order. Rewrite the query to apply an OrderBy clause on the sequence before calling '{method}'.</value>
</data>
<data name="NullTypeMappingInSqlTree" xml:space="preserve">
<value>Null TypeMapping in Sql Tree.</value>
</data>
<data name="UnableToBindMemberToEntityProjection" xml:space="preserve">
<value>Unable to bind '{memberType}' '{member}' to entity projection of '{entityType}'.</value>
</data>
<data name="UnsupportedOperatorForSqlExpression" xml:space="preserve">
<value>Unsupported operator '{nodeType}' specified for expression of type '{expressionType}'.</value>
</data>
<data name="VisitChildrenMustBeOverridden" xml:space="preserve">
<value>VisitChildren must be overridden in class deriving from SqlExpression.</value>
</data>
</root>
18 changes: 3 additions & 15 deletions src/EFCore.Relational/Query/EntityProjectionExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,7 @@ public virtual ColumnExpression BindProperty([NotNull] IProperty property)
&& !property.DeclaringEntityType.IsAssignableFrom(EntityType))
{
throw new InvalidOperationException(
CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface(
"BindProperty",
"IProperty",
EntityType.DisplayName(),
property.Name));
RelationalStrings.UnableToBindMemberToEntityProjection("Property", property.Name, EntityType.DisplayName()));
}

return _propertyExpressionMap[property];
Expand All @@ -190,11 +186,7 @@ public virtual void AddNavigationBinding([NotNull] INavigation navigation, [NotN
&& !navigation.DeclaringEntityType.IsAssignableFrom(EntityType))
{
throw new InvalidOperationException(
CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface(
"AddNavigationBinding",
"INavigation",
EntityType.DisplayName(),
navigation.Name));
RelationalStrings.UnableToBindMemberToEntityProjection("Navigation", navigation.Name, EntityType.DisplayName()));
}

_ownedNavigationMap[navigation] = entityShaper;
Expand All @@ -214,11 +206,7 @@ public virtual EntityShaperExpression BindNavigation([NotNull] INavigation navig
&& !navigation.DeclaringEntityType.IsAssignableFrom(EntityType))
{
throw new InvalidOperationException(
CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface(
"BindNavigation",
"INavigation",
EntityType.DisplayName(),
navigation.Name));
RelationalStrings.UnableToBindMemberToEntityProjection("Navigation", navigation.Name, EntityType.DisplayName()));
}

return _ownedNavigationMap.TryGetValue(navigation, out var expression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ protected override ShapedQueryExpression TranslateLastOrDefault(
if (selectExpression.Orderings.Count == 0)
{
throw new InvalidOperationException(
CoreStrings.LastUsedWithoutOrderBy(returnDefault ?
RelationalStrings.LastUsedWithoutOrderBy(returnDefault ?
nameof(Queryable.LastOrDefault) : nameof(Queryable.Last)));
}

Expand Down Expand Up @@ -1559,7 +1559,7 @@ private ShapedQueryExpression AggregateResultShaper(
Expression.New(
typeof(InvalidOperationException).GetConstructors()
.Single(ci => ci.GetParameters().Length == 1),
Expression.Constant(CoreStrings.NoElements)),
Expression.Constant(CoreStrings.SequenceContainsNoElements)),
resultType);

shaper = Expression.Block(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
{
if (sqlExpression.TypeMapping == null)
{
throw new InvalidOperationException(CoreStrings.NullTypeMappingInSqlTree);
throw new InvalidOperationException(RelationalStrings.NullTypeMappingInSqlTree);
}
}

Expand Down
Loading