The problem in this case was I didn't remove the first argument when I
created the pipe, and so the arguments were the wrong type. But I'd still
like to see a better error message for this.

On Sun, Sep 15, 2019 at 2:51 PM Landon Schropp <[email protected]> wrote:

> Hello!
>
> I'm new to Elixir development, so I'm approaching the language with fresh
> eyes. One of the issues I've run into is difficulty understand the error
> messages from the standard library. For example, today I ran this code:
>
> string
> |> String.replace(string, ~r/[^\[\](){}]/, "")
> |> IO.inspect(label: "\n")
> |> String.codepoints
> |> check_brackets([])
>
> When I run this code through one of my test cases, I get the following
> error:
>
>   1) test math expression (BracketPushTest)
>      test/bracket_push_test.exs:52
>      ** (FunctionClauseError) no function clause matching in Keyword.get/3
>      The following arguments were given to Keyword.get/3:
>
>
>          # 1
>
>                   ""
>
>
>          # 2
>          :insert_replaced
>
>
>          # 3
>          nil
>
>
>              Attempted function clauses (showing 1 out of 1):
>
>
>          def get(keywords, key, default) when is_list(keywords) and
> is_atom(key)
>
>
>      code: assert BracketPush.check_brackets("(((185 + 223.85) * 15) -
> 543)/2") == true
>      stacktrace:
>        (elixir) lib/keyword.ex:195: Keyword.get/3
>        (elixir) lib/string.ex:1372: String.replace/4
>        (bracket_push) lib/bracket_push.ex:15: BracketPush.check_brackets/1
>        test/bracket_push_test.exs:53: (test)
>
>      test/bracket_push_test.exs:52
>      ** (FunctionClauseError) no function clause matching in Keyword.get/3
>      The following arguments were given to Keyword.get/3:
>
>
>          # 1
>
>                   ""
>
>
>          # 2
>          :insert_replaced
>
>
>          # 3
>          nil
>
>
>              Attempted function clauses (showing 1 out of 1):
>
>
>          def get(keywords, key, default) when is_list(keywords) and
> is_atom(key)
>
>
>      code: assert BracketPush.check_brackets("(((185 + 223.85) * 15) -
> 543)/2") == true
>      stacktrace:
>        (elixir) lib/keyword.ex:195: Keyword.get/3
>        (elixir) lib/string.ex:1372: String.replace/4
>        (bracket_push) lib/bracket_push.ex:15: BracketPush.check_brackets/1
>
> As a new language user, it's really hard to understand what I did wrong
> when the error is thrown from inside the inner implementation of
> String.replace/4. In order to debug this, I'd either have to look at the
> inner implementation of String.replace/4 or attempt to fiddle with the
> arguments. My preference would be for standard library functions to guard
> their own interfaces, and throw specific and actionable messages back to
> the developer.
>
> Thanks for taking the time to read!
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/ec0892c5-04b8-4fe7-88b5-e12312483fa6%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/ec0892c5-04b8-4fe7-88b5-e12312483fa6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CANG3DMXR3Ui_Osst4MunMjP_7fdHFHS-%3D8NW0XCWh7duLM0r9g%40mail.gmail.com.

Reply via email to