From ea2357670a6cb2a41c6704dba06b2eb967fbe979 Mon Sep 17 00:00:00 2001 From: Maksim Volkau Date: Tue, 14 May 2024 21:13:38 +0200 Subject: [PATCH] feat: better error msg --- crates/compiler/load/tests/test_reporting.rs | 24 +++++++++++++++----- crates/repl_test/src/tests.rs | 8 +++++-- crates/reporting/src/error/type.rs | 4 ++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/crates/compiler/load/tests/test_reporting.rs b/crates/compiler/load/tests/test_reporting.rs index bbda53a5217..7fa724d357d 100644 --- a/crates/compiler/load/tests/test_reporting.rs +++ b/crates/compiler/load/tests/test_reporting.rs @@ -1665,7 +1665,7 @@ mod test_reporting { f 1 " ), - @r" + @r#" ── TOO FEW ARGS in /code/proj/Main.roc ───────────────────────────────────────── The `f` function expects 2 arguments, but it got only 1: @@ -1675,7 +1675,11 @@ mod test_reporting { Roc does not allow functions to be partially applied. Use a closure to make partial application explicit. - " + + For example: ["a", "b"] |> \list -> Str.joinWith list ", " + + or simplier: ["a", "b"] |> Str.joinWith ", " + "# ); test_report!( @@ -14214,7 +14218,7 @@ In roc, functions are always written as a lambda, like{} 2 |> (Num.sub 3) " ), - @r" + @r#" ── TOO FEW ARGS in /code/proj/Main.roc ───────────────────────────────────────── The `sub` function expects 2 arguments, but it got only 1: @@ -14224,7 +14228,11 @@ In roc, functions are always written as a lambda, like{} Roc does not allow functions to be partially applied. Use a closure to make partial application explicit. - " + + For example: ["a", "b"] |> \list -> Str.joinWith list ", " + + or simplier: ["a", "b"] |> Str.joinWith ", " + "# ); test_report!( @@ -14234,7 +14242,7 @@ In roc, functions are always written as a lambda, like{} 2 |> (Num.sub 3) |> Num.sub 3 " ), - @r" + @r#" ── TOO FEW ARGS in /code/proj/Main.roc ───────────────────────────────────────── The `sub` function expects 2 arguments, but it got only 1: @@ -14244,6 +14252,10 @@ In roc, functions are always written as a lambda, like{} Roc does not allow functions to be partially applied. Use a closure to make partial application explicit. - " + + For example: ["a", "b"] |> \list -> Str.joinWith list ", " + + or simplier: ["a", "b"] |> Str.joinWith ", " + "# ); } diff --git a/crates/repl_test/src/tests.rs b/crates/repl_test/src/tests.rs index 7099e22f19d..ed43a993181 100644 --- a/crates/repl_test/src/tests.rs +++ b/crates/repl_test/src/tests.rs @@ -642,7 +642,7 @@ fn too_few_args() { expect_failure( "Num.add 2", indoc!( - r" + r#" ── TOO FEW ARGS ──────────────────────────────────────────────────────────────── The add function expects 2 arguments, but it got only 1: @@ -652,7 +652,11 @@ fn too_few_args() { Roc does not allow functions to be partially applied. Use a closure to make partial application explicit. - " + + For example: ["a", "b"] |> \list -> Str.joinWith list ", " + + or simplier: ["a", "b"] |> Str.joinWith ", " + "# ), ); } diff --git a/crates/reporting/src/error/type.rs b/crates/reporting/src/error/type.rs index e8313466217..8e839e0ef11 100644 --- a/crates/reporting/src/error/type.rs +++ b/crates/reporting/src/error/type.rs @@ -1237,6 +1237,10 @@ fn to_expr_report<'b>( "Roc does not allow functions to be partially applied. \ Use a closure to make partial application explicit.", ), + alloc.reflow( + r#"For example: ["a", "b"] |> \list -> Str.joinWith list ", ""#, + ), + alloc.reflow(r#"or simplier: ["a", "b"] |> Str.joinWith ", ""#), ]; Report {