avram
avram copied to clipboard
Add more helpful compiler errors if wrong data types are passed as where query arguments
For example, when passing a Time::Span to the gt method to build a query:
BlockQuery.new.time.gt(1.day)
# (should be: BlockQuery.new.time.gt(Time.utc - 1.day))
The error is not referencing the gt method:
In lib/avram/src/avram/type.cr:25:5
25 | parse(value).as(SuccessfulCast).value
^----
Error: no overload matches 'Time::Lucky.parse' with type Time::Span
Difficulty of this will be that the code is meant to handle different types of input. This gt can be called with String as well, for example.
Time::Span should probably never be called. We might be able to just do an overload
def gt(value : Time::Span)
{% raise "You probably meant to pass aTime" %}
end
Not sure if that would work or not, but I'd say we start there at least.
Time::Spanshould probably never be called.
In this case, passing a value of Time::Span is an easy mistake to make. So I think it's a great low-impact solution.