prql icon indicating copy to clipboard operation
prql copied to clipboard

Better error message for missing args

Open aljazerzen opened this issue 3 years ago • 1 comments

from film
select [film_id, lag film_id]

... produces:

Error: 
   ╭─[:2:18]
   │
 2 │ select [film_id, lag film_id]
   ·                  ─────┬─────  
   ·                       ╰─────── function std.select, param `columns` expected type `column`, but found type `func infer -> column`
───╯

We should add a hint here, saying "Have you forgot an argument to function std.lag?"

This error is thrown here: https://github.com/prql/prql/blob/9831c244d4bf3331744de9536d5639bbaab361bc/prql-compiler/src/semantic/type_resolver.rs#L73-L78

TODO:

  • check if found_ty is a Ty::Function & check that expected_ty is not,
  • add hint via calling Error::with_help(...).

Name of the function called can be obtained by destructing found.kind and matching it to ExprKind::Closure, which contains Closure::name. If expr does not match or closure does not specify a name, fallback to a message "Have you forgot an argument in this function call?"

aljazerzen avatar Nov 28 '22 09:11 aljazerzen

Good onboarding issue! I can take a swing at this soon if no one gets to it (I wouldn't start before midweek though)

max-sixty avatar Nov 28 '22 09:11 max-sixty