Skip to content

Commit

Permalink
Fix #16712 Convert exceptions messages to resource strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Muppets committed Feb 27, 2020
1 parent 233856f commit 51f09aa
Show file tree
Hide file tree
Showing 62 changed files with 676 additions and 250 deletions.
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 @@ -156,4 +156,16 @@
<data name="UpdateConflict" xml:space="preserve">
<value>Conflicts were detected for item with id '{itemId}'.</value>
</data>
<data name="NonEmbeddedIncludeNotSupported" xml:space="preserve">
<value>Non-embedded IncludeExpression is not supported: {expression}</value>
</data>
<data name="NavigationPropertyIsNotAnEmbeddedEntity" xml:space="preserve">
<value>Navigation '{entityType}.{navigationName}' doesn't point to an embedded entity.</value>
</data>
<data name="OffsetRequiresLimit" xml:space="preserve">
<value>Offset is not supported without Limit.</value>
</data>
<data name="ReverseRequiresOffsetOrLimit" xml:space="preserve">
<value>Reverse is not supported without Limit or Offset.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq.Expressions;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
Expand Down Expand Up @@ -452,8 +453,7 @@ protected override Expression VisitExtension(Expression extensionExpression)

if (!includeExpression.Navigation.IsEmbedded())
{
throw new InvalidOperationException(
"Non-embedded IncludeExpression is not supported: " + includeExpression.Print());
throw new InvalidOperationException(CosmosStrings.NonEmbeddedIncludeNotSupported(includeExpression.Print()));
}

_includedNavigations.Push(includeExpression.Navigation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
Expand Down Expand Up @@ -217,8 +218,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
if (includeExpression.Navigation.IsOnDependent
|| includeExpression.Navigation.ForeignKey.DeclaringEntityType.IsDocumentRoot())
{
throw new InvalidOperationException(
"Non-embedded IncludeExpression is not supported: " + includeExpression.Print());
throw new InvalidOperationException(CosmosStrings.NonEmbeddedIncludeNotSupported(includeExpression.Print()));
}

_pendingIncludes.Add(includeExpression);
Expand Down Expand Up @@ -298,8 +298,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
if (includeExpression.Navigation.IsOnDependent
|| includeExpression.Navigation.ForeignKey.DeclaringEntityType.IsDocumentRoot())
{
throw new InvalidOperationException(
"Non-embedded IncludeExpression is not supported: " + includeExpression.Print());
throw new InvalidOperationException(CosmosStrings.NonEmbeddedIncludeNotSupported(includeExpression.Print()));
}

var isFirstInclude = _pendingIncludes.Count == 0;
Expand Down
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.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
Expand Down Expand Up @@ -83,7 +84,7 @@ protected override Expression VisitExtension(Expression node)
if (node is SqlExpression sqlExpression
&& sqlExpression.TypeMapping == null)
{
throw new InvalidOperationException("Null TypeMapping in Sql Tree");
throw new InvalidOperationException(CoreStrings.NullTypeMappingInSqlTree);
}

return base.VisitExtension(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq.Expressions;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Utilities;
Expand Down Expand Up @@ -116,7 +117,8 @@ public virtual Expression BindProperty([NotNull] IProperty property, bool client
&& !property.DeclaringEntityType.IsAssignableFrom(EntityType))
{
throw new InvalidOperationException(
$"Called EntityProjectionExpression.GetProperty() with incorrect IProperty. EntityType:{EntityType.DisplayName()}, Property:{property.Name}");
CoreStrings.EntityProjectionExpressionCalledWithIncorrectInterface(
"GetProperty", nameof(IProperty), EntityType.DisplayName(), $"Property:{property.Name}"));
}

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

if (!_navigationExpressionsCache.TryGetValue(navigation, out var expression))
Expand Down
5 changes: 4 additions & 1 deletion src/EFCore.Cosmos/Query/Internal/ObjectAccessExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System;
using System.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Utilities;
Expand All @@ -30,7 +32,8 @@ public ObjectAccessExpression([NotNull] INavigation navigation, [NotNull] Expres
if (Name == null)
{
throw new InvalidOperationException(
$"Navigation '{navigation.DeclaringEntityType.DisplayName()}.{navigation.Name}' doesn't point to an embedded entity.");
CosmosStrings.NavigationPropertyIsNotAnEmbeddedEntity(
navigation.DeclaringEntityType.DisplayName(), navigation.Name));
}

Navigation = navigation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Utilities;
Expand Down Expand Up @@ -37,7 +39,8 @@ public ObjectArrayProjectionExpression(
if (Name == null)
{
throw new InvalidOperationException(
$"Navigation '{navigation.DeclaringEntityType.DisplayName()}.{navigation.Name}' doesn't point to an embedded entity.");
CosmosStrings.NavigationPropertyIsNotAnEmbeddedEntity(
navigation.DeclaringEntityType.DisplayName(), navigation.Name));
}

Navigation = navigation;
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore.Cosmos/Query/Internal/QuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq.Expressions;
using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
Expand Down Expand Up @@ -243,7 +244,7 @@ protected override Expression VisitSelect(SelectExpression selectExpression)
else
{
// TODO: See Issue#18923
throw new InvalidOperationException("Cosmos Sql API does not support Offset without Limit.");
throw new InvalidOperationException(CosmosStrings.OffsetRequiresLimit);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/EFCore.Cosmos/Query/Internal/SelectExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Linq;
using System.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Utilities;
Expand Down Expand Up @@ -343,7 +345,7 @@ public virtual void ReverseOrderings()
if (Limit != null
|| Offset != null)
{
throw new InvalidOperationException("Cosmos: Reverse without Limit or Offset.");
throw new InvalidOperationException(CosmosStrings.ReverseRequiresOffsetOrLimit);
}

var existingOrderings = _orderings.ToArray();
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore.Cosmos/Query/Internal/SqlBinaryExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
Expand Down Expand Up @@ -44,7 +45,7 @@ public class SqlBinaryExpression : SqlExpression
private static ExpressionType VerifyOperator(ExpressionType operatorType)
=> _allowedOperators.Contains(operatorType)
? operatorType
: throw new InvalidOperationException("Unsupported Binary operator type specified.");
: throw new InvalidOperationException(CoreStrings.UnsupportedBinaryOperator);

/// <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.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;

Expand Down Expand Up @@ -52,7 +53,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("VisitChildren must be overridden in class deriving from SqlExpression");
=> throw new InvalidOperationException(CoreStrings.VisitChildrenMustBeOverridden);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private SqlExpression ApplyTypeMappingOnSqlBinary(
break;

default:
throw new InvalidOperationException("Incorrect operatorType for SqlBinaryExpression");
throw new InvalidOperationException(CoreStrings.IncorrectOperatorType);
}

return new SqlBinaryExpression(
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore.Cosmos/Query/Internal/SqlUnaryExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
Expand All @@ -27,7 +28,7 @@ public class SqlUnaryExpression : SqlExpression
private static ExpressionType VerifyOperator(ExpressionType operatorType)
=> _allowedOperators.Contains(operatorType)
? operatorType
: throw new InvalidOperationException("Unsupported Unary operator type specified.");
: throw new InvalidOperationException(CoreStrings.UnsupportedUnary);

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

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

6 changes: 3 additions & 3 deletions src/EFCore.Design/Properties/DesignStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,6 @@ Change your target project to the migrations project by using the Package Manage
<data name="NoLanguageService" xml:space="preserve">
<value>The project language '{language}' isn't supported by the built-in {service} service. You can try looking for an additional NuGet package which supports this language; moving your DbContext type to a C# class library referenced by this project; or manually implementing and registering the design-time service for programming language.</value>
</data>
<data name="RevertingMigration" xml:space="preserve">
<value>Reverting migration '{name}'.</value>
</data>
<data name="FindingReferencedServices" xml:space="preserve">
<value>Finding design-time services referenced by assembly '{startupAssembly}'.</value>
</data>
Expand Down Expand Up @@ -363,4 +360,7 @@ Change your target project to the migrations project by using the Package Manage
<data name="UsingHostingServices" xml:space="preserve">
<value>Using application service provider from Microsoft.Extensions.Hosting.</value>
</data>
<data name="UnhandledEnumValue" xml:space="preserve">
<value>Unhandled enum value '{enumValue}'.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
Expand Down Expand Up @@ -746,7 +747,7 @@ private void GenerateProperty(IProperty property, bool useDataAnnotations)
: nameof(PropertyBuilder.ValueGeneratedOnAddOrUpdate),
ValueGenerated.OnUpdate => nameof(PropertyBuilder.ValueGeneratedOnUpdate),
ValueGenerated.Never => nameof(PropertyBuilder.ValueGeneratedNever),
_ => throw new InvalidOperationException($"Unhandled enum value '{nameof(ValueGenerated)}.{valueGenerated}'")
_ => throw new InvalidOperationException(DesignStrings.UnhandledEnumValue($"{nameof(ValueGenerated)}.{valueGenerated}"))
};

lines.Add($".{methodName}()");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.IO;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;

Expand Down Expand Up @@ -79,17 +80,17 @@ public override ScaffoldedModel GenerateModel(

if (options.ContextName == null)
{
throw new ArgumentException($"{nameof(options.ContextName)} cannot be null", nameof(options));
throw new ArgumentException(CoreStrings.ArgumentPropertyNull(nameof(options.ContextName), nameof(options)), nameof(options));
}

if (options.ConnectionString == null)
{
throw new ArgumentException($"{nameof(options.ConnectionString)} cannot be null", nameof(options));
throw new ArgumentException(CoreStrings.ArgumentPropertyNull(nameof(options.ConnectionString), nameof(options)), nameof(options));
}

if (options.ModelNamespace == null)
{
throw new ArgumentException($"{nameof(options.ModelNamespace)} cannot be null", nameof(options));
throw new ArgumentException(CoreStrings.ArgumentPropertyNull(nameof(options.ModelNamespace), nameof(options)), nameof(options));
}

var generatedCode = CSharpDbContextGenerator.WriteCode(
Expand Down
14 changes: 14 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.

Loading

0 comments on commit 51f09aa

Please sign in to comment.