avram icon indicating copy to clipboard operation
avram copied to clipboard

Add more helpful compiler errors if wrong data types are passed as where query arguments

Open wout opened this issue 3 years ago • 3 comments

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

wout avatar Jan 17 '22 17:01 wout

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.

matthewmcgarvey avatar Jan 17 '22 18:01 matthewmcgarvey

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.

jwoertink avatar Jan 17 '22 18:01 jwoertink

Time::Span should 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.

wout avatar Jan 17 '22 19:01 wout