Skip to content

Commit

Permalink
Throw better exception message for client eval
Browse files Browse the repository at this point in the history
Fixes #16133 and also partial fix for #15937

This is far from perfect and needs some further work. For example, see #17236

No issues reference #14935 any more; new issues cover things not fixed here but which were refeceing that issue.
  • Loading branch information
ajcvickers authored and smitpatel committed Aug 21, 2019
1 parent f1709f4 commit 6f0a799
Show file tree
Hide file tree
Showing 93 changed files with 3,203 additions and 5,155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
Expand Down Expand Up @@ -380,7 +381,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
return _clientEval ? base.VisitExtension(includeExpression) : null;

default:
throw new InvalidOperationException(new ExpressionPrinter().Print(extensionExpression));
throw new InvalidOperationException(CoreStrings.TranslationFailed(extensionExpression.Print()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
Expand Down Expand Up @@ -58,7 +59,7 @@ public CosmosQueryableMethodTranslatingExpressionVisitor(
/// </summary>
public override ShapedQueryExpression TranslateSubquery(Expression expression)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(expression.Print()));
}

/// <summary>
Expand Down Expand Up @@ -91,7 +92,7 @@ protected override ShapedQueryExpression CreateShapedQueryExpression(Type elemen
/// </summary>
protected override ShapedQueryExpression TranslateAll(ShapedQueryExpression source, LambdaExpression predicate)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print()));
}

/// <summary>
Expand All @@ -102,7 +103,7 @@ protected override ShapedQueryExpression TranslateAll(ShapedQueryExpression sour
/// </summary>
protected override ShapedQueryExpression TranslateAny(ShapedQueryExpression source, LambdaExpression predicate)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print()));
}

/// <summary>
Expand All @@ -118,7 +119,7 @@ protected override ShapedQueryExpression TranslateAverage(ShapedQueryExpression
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
{
throw new InvalidOperationException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print()));
}

if (selector != null)
Expand Down Expand Up @@ -159,7 +160,8 @@ protected override ShapedQueryExpression TranslateCast(ShapedQueryExpression sou
/// </summary>
protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression source1, ShapedQueryExpression source2)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(
source1.Print() + "; " + source2.Print()));
}

/// <summary>
Expand All @@ -170,7 +172,7 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s
/// </summary>
protected override ShapedQueryExpression TranslateContains(ShapedQueryExpression source, Expression item)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(item.Print()));
}

/// <summary>
Expand All @@ -186,7 +188,7 @@ protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression so
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
{
throw new InvalidOperationException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print()));
}

if (predicate != null)
Expand Down Expand Up @@ -217,7 +219,7 @@ protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression so
/// </summary>
protected override ShapedQueryExpression TranslateDefaultIfEmpty(ShapedQueryExpression source, Expression defaultValue)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(defaultValue.Print()));
}

/// <summary>
Expand All @@ -241,7 +243,7 @@ protected override ShapedQueryExpression TranslateDistinct(ShapedQueryExpression
/// </summary>
protected override ShapedQueryExpression TranslateElementAtOrDefault(ShapedQueryExpression source, Expression index, bool returnDefault)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(index.Print()));
}

/// <summary>
Expand All @@ -252,7 +254,8 @@ protected override ShapedQueryExpression TranslateElementAtOrDefault(ShapedQuery
/// </summary>
protected override ShapedQueryExpression TranslateExcept(ShapedQueryExpression source1, ShapedQueryExpression source2)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(
source1.Print() + "; " + source2.Print()));
}

/// <summary>
Expand Down Expand Up @@ -287,7 +290,8 @@ protected override ShapedQueryExpression TranslateFirstOrDefault(ShapedQueryExpr
/// </summary>
protected override ShapedQueryExpression TranslateGroupBy(ShapedQueryExpression source, LambdaExpression keySelector, LambdaExpression elementSelector, LambdaExpression resultSelector)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(
keySelector.Print() + "; " + elementSelector.Print() + "; " + resultSelector.Print()));
}

/// <summary>
Expand All @@ -298,7 +302,8 @@ protected override ShapedQueryExpression TranslateGroupBy(ShapedQueryExpression
/// </summary>
protected override ShapedQueryExpression TranslateGroupJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(
outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print()));
}

/// <summary>
Expand All @@ -309,7 +314,8 @@ protected override ShapedQueryExpression TranslateGroupJoin(ShapedQueryExpressio
/// </summary>
protected override ShapedQueryExpression TranslateIntersect(ShapedQueryExpression source1, ShapedQueryExpression source2)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(
source1.Print() + "; " + source2.Print()));
}

/// <summary>
Expand All @@ -320,7 +326,8 @@ protected override ShapedQueryExpression TranslateIntersect(ShapedQueryExpressio
/// </summary>
protected override ShapedQueryExpression TranslateJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(
outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print()));
}

/// <summary>
Expand Down Expand Up @@ -356,7 +363,8 @@ protected override ShapedQueryExpression TranslateLastOrDefault(ShapedQueryExpre
/// </summary>
protected override ShapedQueryExpression TranslateLeftJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(
outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print()));
}

/// <summary>
Expand All @@ -372,7 +380,7 @@ protected override ShapedQueryExpression TranslateLongCount(ShapedQueryExpressio
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
{
throw new InvalidOperationException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print()));
}

if (predicate != null)
Expand Down Expand Up @@ -407,7 +415,7 @@ protected override ShapedQueryExpression TranslateMax(ShapedQueryExpression sour
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
{
throw new InvalidOperationException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print()));
}

if (selector != null)
Expand Down Expand Up @@ -435,7 +443,7 @@ protected override ShapedQueryExpression TranslateMin(ShapedQueryExpression sour
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
{
throw new InvalidOperationException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print()));
}

if (selector != null)
Expand All @@ -458,7 +466,7 @@ protected override ShapedQueryExpression TranslateMin(ShapedQueryExpression sour
/// </summary>
protected override ShapedQueryExpression TranslateOfType(ShapedQueryExpression source, Type resultType)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(source.Print()));
}

/// <summary>
Expand All @@ -477,7 +485,7 @@ protected override ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression
return source;
}

throw new InvalidOperationException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(keySelector.Print()));
}

/// <summary>
Expand All @@ -488,7 +496,7 @@ protected override ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression
/// </summary>
protected override ShapedQueryExpression TranslateReverse(ShapedQueryExpression source)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(source.Print()));
}

/// <summary>
Expand All @@ -507,7 +515,7 @@ protected override ShapedQueryExpression TranslateSelect(ShapedQueryExpression s
var selectExpression = (SelectExpression)source.QueryExpression;
if (selectExpression.IsDistinct)
{
throw new InvalidOperationException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print()));
}

var newSelectorBody = ReplacingExpressionVisitor.Replace(selector.Parameters.Single(), source.ShaperExpression, selector.Body);
Expand All @@ -526,7 +534,8 @@ protected override ShapedQueryExpression TranslateSelect(ShapedQueryExpression s
/// </summary>
protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpression source, LambdaExpression collectionSelector, LambdaExpression resultSelector)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(
collectionSelector.Print() + "; " + resultSelector.Print()));
}

/// <summary>
Expand All @@ -537,7 +546,7 @@ protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpressi
/// </summary>
protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpression source, LambdaExpression selector)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print()));
}

/// <summary>
Expand Down Expand Up @@ -582,7 +591,7 @@ protected override ShapedQueryExpression TranslateSkip(ShapedQueryExpression sou
return source;
}

throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(count.Print()));
}

/// <summary>
Expand All @@ -593,7 +602,7 @@ protected override ShapedQueryExpression TranslateSkip(ShapedQueryExpression sou
/// </summary>
protected override ShapedQueryExpression TranslateSkipWhile(ShapedQueryExpression source, LambdaExpression predicate)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print()));
}

/// <summary>
Expand All @@ -609,7 +618,7 @@ protected override ShapedQueryExpression TranslateSum(ShapedQueryExpression sour
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
{
throw new InvalidOperationException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print()));
}

if (selector != null)
Expand Down Expand Up @@ -644,7 +653,7 @@ protected override ShapedQueryExpression TranslateTake(ShapedQueryExpression sou
return source;
}

throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(count.Print()));
}

/// <summary>
Expand All @@ -655,7 +664,7 @@ protected override ShapedQueryExpression TranslateTake(ShapedQueryExpression sou
/// </summary>
protected override ShapedQueryExpression TranslateTakeWhile(ShapedQueryExpression source, LambdaExpression predicate)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print()));
}

/// <summary>
Expand All @@ -674,7 +683,7 @@ protected override ShapedQueryExpression TranslateThenBy(ShapedQueryExpression s
return source;
}

throw new InvalidOperationException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(keySelector.Print()));
}

/// <summary>
Expand All @@ -685,7 +694,8 @@ protected override ShapedQueryExpression TranslateThenBy(ShapedQueryExpression s
/// </summary>
protected override ShapedQueryExpression TranslateUnion(ShapedQueryExpression source1, ShapedQueryExpression source2)
{
throw new NotImplementedException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(
source1.Print() + "; " + source2.Print()));
}

/// <summary>
Expand All @@ -704,7 +714,7 @@ protected override ShapedQueryExpression TranslateWhere(ShapedQueryExpression so
return source;
}

throw new InvalidOperationException("Unable to translate Where expression: " + new ExpressionPrinter().Print(predicate));
throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print()));
}

private SqlExpression TranslateExpression(Expression expression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
|| fk.DeclaringEntityType.IsDocumentRoot())
{
throw new InvalidOperationException(
"Non-embedded IncludeExpression " + new ExpressionPrinter().Print(includeExpression));
"Non-embedded IncludeExpression " + includeExpression.Print());
}

// These are the expressions added by JObjectInjectingExpressionVisitor
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 System.Reflection;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
Expand Down Expand Up @@ -113,7 +114,7 @@ private Expression BindProperty(Expression source, string propertyName, Type typ
: Expression.Convert(result, type);
}

throw new InvalidOperationException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(source.Print()));
}

private Expression BindProperty(EntityProjectionExpression entityProjectionExpression, IProperty property)
Expand Down Expand Up @@ -299,7 +300,7 @@ protected override Expression VisitParameter(ParameterExpression parameterExpres
Expression.Constant(parameterExpression.Name));
}

throw new InvalidOperationException();
throw new InvalidOperationException(CoreStrings.TranslationFailed(parameterExpression.Print()));
}

private static readonly MethodInfo _getParameterValueMethodInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
Expand Down Expand Up @@ -338,7 +340,10 @@ protected override ShapedQueryExpression TranslateSelectMany(
if (correlated)
{
// TODO visit inner with outer parameter;
throw new NotImplementedException();
// See #17236
throw new InvalidOperationException(CoreStrings.TranslationFailed(
collectionSelector.Print() + "; " + resultSelector.Print()));

}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Diagnostics/RelationalEventId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ private enum Id
/// This event is in the <see cref="DbLoggerCategory.Query" /> category.
/// </para>
/// </summary>
[Obsolete]
[Obsolete("Automatic client evaluation is no longer supported. This event is no longer generated.")]
public static readonly EventId QueryClientEvaluationWarning = MakeQueryId(Id.QueryClientEvaluationWarning);

/// <summary>
Expand Down
Loading

0 comments on commit 6f0a799

Please sign in to comment.