Skip to content

Commit 1df49c0

Browse files
committed
Fix wrapped exception for no index
1 parent 85bc118 commit 1df49c0

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/CouchDB.Driver/CouchQueryProvider.cs

+16-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Linq;
1010
using System.Linq.Expressions;
1111
using System.Reflection;
12+
using System.Runtime.ExceptionServices;
1213

1314
namespace CouchDB.Driver
1415
{
@@ -37,14 +38,22 @@ public override object Execute(Expression expression, bool completeResponse)
3738
// Remove from the expressions tree all IQueryable methods not supported by CouchDB and put them into the list
3839
var unsupportedMethodCallExpressions = new List<MethodCallExpression>();
3940
expression = RemoveUnsupportedMethodExpressions(expression, out var hasUnsupportedMethods, unsupportedMethodCallExpressions);
40-
41+
4142
var body = Translate(ref expression);
4243
Type elementType = TypeSystem.GetElementType(expression.Type);
4344

4445
// Create generic GetCouchList method and invoke it, sending the request to CouchDB
4546
MethodInfo method = typeof(CouchQueryProvider).GetMethod(nameof(CouchQueryProvider.GetCouchList));
4647
MethodInfo generic = method.MakeGenericMethod(elementType);
47-
var result = generic.Invoke(this, new[] { body });
48+
object result = null;
49+
try
50+
{
51+
result = generic.Invoke(this, new[] { body });
52+
}
53+
catch (TargetInvocationException ex)
54+
{
55+
ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
56+
}
4857

4958
// If no unsupported methods, return the result
5059
if (!hasUnsupportedMethods)
@@ -73,7 +82,7 @@ private string Translate(ref Expression e)
7382
}
7483

7584
public object GetCouchList<T>(string body)
76-
{
85+
{
7786
FindResult<T> result = _flurlClient
7887
.Request(_connectionString)
7988
.AppendPathSegments(_db, "_find")
@@ -82,7 +91,7 @@ public object GetCouchList<T>(string body)
8291
.SendRequest();
8392

8493
var couchList = new CouchList<T>(result.Docs.ToList(), result.Bookmark, result.ExecutionStats);
85-
return couchList;
94+
return couchList;
8695
}
8796

8897
private Expression RemoveUnsupportedMethodExpressions(Expression expression, out bool hasUnsupportedMethods, IList<MethodCallExpression> unsupportedMethodCallExpressions)
@@ -177,7 +186,7 @@ MethodInfo FindEnumerableMethod()
177186
throw;
178187
}
179188
}
180-
189+
181190
private object GetArgumentValueFromExpression(Expression e)
182191
{
183192
if (e is ConstantExpression c)
@@ -190,7 +199,7 @@ private object GetArgumentValueFromExpression(Expression e)
190199
}
191200
throw new NotImplementedException($"Expression of type {e.NodeType} not supported.");
192201
}
193-
202+
194203
private static MethodInfo FindEnumerableMinMax(MethodInfo queryableMethodInfo)
195204
{
196205
Type[] genericParams = queryableMethodInfo.GetGenericArguments();
@@ -203,6 +212,6 @@ private static MethodInfo FindEnumerableMinMax(MethodInfo queryableMethodInfo)
203212
enumerableMethodInfo.ReturnType == genericParams[1];
204213
});
205214
return finalMethodInfo;
206-
}
215+
}
207216
}
208217
}

0 commit comments

Comments
 (0)