Conversation
…ctions A value that does not convert to the property type (for example `Age == "abc"`, `Rating > abc`, or an int overflow) threw FormatException or OverflowException. It now throws ParsingException, with the original exception as the inner exception. An invalid sort direction now throws QueryKitParsingException instead of ArgumentException. An unknown logical operator throws QueryKitParsingException instead of a plain Exception. All of these types derive from QueryKitException. BREAKING CHANGE: a bad filter value throws ParsingException, not FormatException or OverflowException. An invalid sort direction throws QueryKitParsingException, not ArgumentException. An unknown logical operator throws QueryKitParsingException, not System.Exception. Catch QueryKitException to handle all of them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes bad values, bad sort directions, and unknown logical operators throw QueryKit exceptions. This is a breaking change. It is one of the six breaking changes that were removed from #114 so that main stays compatible with v1.14.2.
Status: for later consideration. Do not merge this PR now. The captain decides on each breaking change separately. If this change is accepted, it needs a major version.
Main already accepts more than one space before a sort direction (
Age desc). This PR adds only the three exception type changes.Old behavior (v1.14.2 and main)
FormatExceptionorOverflowExceptionfromApplyQueryKitFilter.ArgumentException.System.Exception.New behavior
ParsingException. The original exception is the inner exception.QueryKitParsingException.QueryKitParsingException.All three new types derive from
QueryKitException.Example
Proof from the
verify-querykitharness. Each row gives the same result in memory and on Postgres.Rating == "abc"FormatExceptionParsingException, inner message "The input string 'abc' was not in a correct format."Rating == 99999999999OverflowExceptionParsingException, inner message "Value was either too large or too small for an Int32."Rating sidewaysArgumentExceptionQueryKitParsingException: "Invalid direction: sideways. Allowed values are 'asc' and 'desc'."Justification
The README says that
QueryKitExceptionis the base class of all QueryKit exceptions, and that a consumer can catch it. In v1.14.2, some bad filters escape this catch asFormatException,OverflowException,ArgumentException, orSystem.Exception. As a result, the API returns a 500 for a client error.After the change, one
catch (QueryKitException)handles every bad filter and every bad sort. The break is limited to a consumer that catches the old specific types. That consumer can catchQueryKitExceptioninstead. The inner exception keeps the original details.Migration
Catch
QueryKitException, notFormatException,OverflowException,ArgumentException, orException.Tests
invalid_value_throws_parsing_exception,invalid_sort_direction_throws_query_kit_parsing_exception, andunknown_logical_operator_throws_query_kit_parsing_exception.invalid_value_throws_parsing_exception.dotnet test: 358 unit tests and 272 integration tests pass.