Skip to content

Commit 391733e

Browse files
committed
fix(operators)!: throw QueryKitParsingException for an unknown logical operator
LogicalOperator.GetByOperatorString threw System.Exception for an operator that it does not know. It now throws QueryKitParsingException with the same message. QueryKitParsingException derives from QueryKitException. BREAKING CHANGE: an unknown logical operator throws QueryKitParsingException, not System.Exception. Catch QueryKitParsingException or QueryKitException instead.
1 parent 94beca6 commit 391733e

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎QueryKit.UnitTests/FilterParsingRegressionTests.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,14 @@ public void has_returns_matching_rows(string input, string[] expectedTitles)
317317
result.Select(x => x.Title).Should().BeEquivalentTo(expectedTitles);
318318
}
319319

320+
[Fact]
321+
public void unknown_logical_operator_throws_query_kit_parsing_exception()
322+
{
323+
var act = () => LogicalOperator.GetByOperatorString("xor");
324+
325+
act.Should().Throw<QueryKitParsingException>().WithMessage("Operator xor is not supported");
326+
}
327+
320328
private static TResult WithCulture<TResult>(string cultureName, Func<TResult> action)
321329
{
322330
var originalCulture = CultureInfo.CurrentCulture;

‎QueryKit/Operators/LogicalOperator.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace QueryKit.Operators;
33
using System.Linq.Expressions;
44
using Ardalis.SmartEnum;
55
using Configuration;
6+
using Exceptions;
67

78
public abstract class LogicalOperator : SmartEnum<LogicalOperator>
89
{
@@ -15,7 +16,7 @@ public static LogicalOperator GetByOperatorString(string op)
1516
var logicalOperator = List.FirstOrDefault(x => x.Operator() == op);
1617
if (logicalOperator == null)
1718
{
18-
throw new Exception($"Operator {op} is not supported");
19+
throw new QueryKitParsingException($"Operator {op} is not supported");
1920
}
2021
return logicalOperator;
2122
}

0 commit comments

Comments
 (0)