prql icon indicating copy to clipboard operation
prql copied to clipboard

feat: Better error message for missing args

Open JettChenT opened this issue 2 years ago • 3 comments

Addresses #1171

JettChenT avatar Jan 01 '23 13:01 JettChenT

Looks good to me.

Can you add a test, similar to this?

aljazerzen avatar Jan 01 '23 13:01 aljazerzen

Hi! Are there any methods for pasting the output into the test program?

Here's my current code snippet for testing:

#[test]
fn test_hint_missing_args(){
    assert_display_snapshot!(compile(r###"
    from film
    select [film_id, lag film_id]
    "###).unwrap_err(), @r###"
    Error:
       ╭─[:3:22]
       │
     2 │  select [film_id, lag film_id]
       ·                   ─────┬─────
       ·                        ╰─────── function std.select, param `columns` expected type `column`, but found type `func infer -> column`
       ·
       · Help: Have you forgot an argument to function `lag`
    ───╯
    "###)
}

Result of the test:

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
-old snapshot
+new results
────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    0     0 │ Error:␊
    1     1 │    ╭─[:3:22]␊
    2     2 │    │␊
    3       │- 2 │  select [film_id, lag film_id]␊
    4       │-   ·                   ─────┬─────␊
    5       │-   ·                        ╰─────── function std.select, param `columns` expected type `column`, but found type `func infer -> column`␊
          3 │+ 3 │     select [film_id, lag film_id]␊
          4 │+   ·                      ─────┬─────␊
          5 │+   ·                           ╰─────── function std.select, param `columns` expected type `column`, but found type `func infer -> column`␊
    6     6 │    ·␊
    7     7 │    · Help: Have you forgot an argument to function `lag`␊
    8       │-───╯
          8 │+───╯␊
────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

I have tried directly copy and pasting from terminal, as well as piping the results to an external file.

JettChenT avatar Jan 01 '23 13:01 JettChenT

Yes there are. We are using cargo-insta. In your case, you need:

$ cargo install cargo-insta
$ cargo insta review

aljazerzen avatar Jan 01 '23 17:01 aljazerzen

Thanks @JettChenT ! Great first PR!

Re accepting the snapshots — the lines that @aljazerzen wrote are the closest way. There are also some pre-written tasks if you want to use those, as discussed in https://github.com/PRQL/prql/blob/main/DEVELOPMENT.md

max-sixty avatar Jan 01 '23 20:01 max-sixty

@aljazerzen @max-sixty Thanks for the help! I have updated the test file and fixed the grammar issue.

JettChenT avatar Jan 02 '23 00:01 JettChenT

Thanks a lot @JettChenT ! And welcome to PRQL!

max-sixty avatar Jan 02 '23 00:01 max-sixty