Skip to content

A value that does not convert on a HasConversion<string> property throws FormatException, not ParsingException #219

Open

Description

@pdevito3

Problem

A single value on a property configured with HasConversion<string>() goes to the (string) constructor of the property type. If the constructor rejects the value, the caller gets the exception of the constructor, not a QueryKit exception:

// WrappedId(string value) : this(int.Parse(value))
var config = new QueryKitConfiguration(c => c.Property<WrappedIdRow>(x => x.Id).HasConversion<string>());
rows.ApplyQueryKitFilter("""Id == "abc" """, config).ToList();
// System.FormatException: The input string 'abc' was not in a correct format.

The constructor runs inside the expression (Expression.New), so the exception comes when the query runs, not when the filter is parsed. For other types, a value that does not convert throws ParsingException with Value, PropertyName, and TargetType at parse time.

Expected

Id == "abc" throws ParsingException with Value = abc, PropertyName = Id, and TargetType = WrappedId, the same as a list item does after the fix for #217.

Notes

Found while reviewing #218. The fix for #217 handles list items only.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions