Skip to content

Commit 6f35a04

Browse files
committed
Wrap ParseException into ExpressionParseException
1 parent ebcc48c commit 6f35a04

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

Runtime/ExpressionParser.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,24 @@ public Expression<T> Compile(string input, ExpresionContext<T> context, bool cac
2626
_parserCached = _parserCached ?? CreateParser();
2727

2828
ExprBuilder builder;
29-
if (cache)
29+
try
3030
{
31-
if (!_builderCached.TryGetValue(input, out builder))
31+
if (cache)
32+
{
33+
if (!_builderCached.TryGetValue(input, out builder))
34+
{
35+
builder = _parserCached.Parse(input);
36+
_builderCached.Add(input, builder);
37+
}
38+
}
39+
else
3240
{
3341
builder = _parserCached.Parse(input);
34-
_builderCached.Add(input, builder);
3542
}
3643
}
37-
else
44+
catch (ParseException parseException)
3845
{
39-
builder = _parserCached.Parse(input);
46+
throw new ExpressionParseException(input, parseException);
4047
}
4148

4249
return builder.Invoke(context);
@@ -368,4 +375,12 @@ public FunctionNotDefinedException(string name, string reason) : base(
368375
{
369376
}
370377
}
378+
379+
public class ExpressionParseException : Exception
380+
{
381+
public ExpressionParseException(string expression, ParseException parseException)
382+
: base($"Failed to parse expression '{expression}'{Environment.NewLine}{parseException.Message}")
383+
{
384+
}
385+
}
371386
}

0 commit comments

Comments
 (0)