yutannihilation / savvy

A simple R extension interface using Rust
https://yutannihilation.github.io/savvy/guide/
MIT License
70 stars 4 forks source link

Better error message for invalid type argument? #264

Closed eitsupi closed 4 months ago

eitsupi commented 4 months ago

If we currently pass the wrong type of argument to a function created with savvy, we don't know which argument type was incorrect because it does not show up in the error message. It would be great if we could identify which function or argument is the cause.

prqlr::prql_compile(1, 1)
#> Error: Unexpected type: expected: character
#>   actual: double

Created on 2024-06-11 with reprex v2.1.0

yutannihilation commented 4 months ago

I think I can do better. What error message do you expect?

eitsupi commented 4 months ago

I was thinking that it would be nice if the Rust side argument name was added in the error message.

That is, since I believe the following function is used here

pub fn compile(
    prql_query: &str,
    target: &str,
    format: bool,
    signature_comment: bool,
) -> savvy::Result<Sexp> {

Like:

#> Error: Unexpected type for the `prql_query` argument:
#>   expected: character
#>   actual: double
yutannihilation commented 4 months ago

Not perfect, but should be better now. I hope https://github.com/yutannihilation/savvy/issues/251 will allow us to create nicer error messages on R's side.

> to_upper(1L)
Error: Argument `x` must be character, not integer
eitsupi commented 4 months ago

Awesome! Thanks for the quick update!