Elixir: Give helpful error message if a string is used to name a GenServer/GenEvent/Agent etc.

Created on 31 Oct 2015  路  7Comments  路  Source: elixir-lang/elixir

I recently came across an exception when I tried to name a GenServer using a string. The same will happen for GenEvent, Supervisor, Agent etc.

iex(1)> pid = GenEvent.start_link(name: "this is a test")
** (CaseClauseError) no case clause matching: "this is a test"
    (elixir) lib/gen_event.ex:375: GenEvent.do_start/2
iex(1)> pid = GenEvent.start_link(name: :this_is_a_test)
{:ok, #PID<0.60.0>}

Instead of (CaseClauseError) no case clause matching: <string> would it be possible to match on name keyword being a string and throw a more helpful error message?

Elixir Bug Starter

Most helpful comment

Thank you @bill-mybiz! @TattdCodeMonkey looking back I may have closed this a bit too hastily, sorry about that. Since this is a common case, let's definitely improve the error message, both on start_link and whereis.

All 7 comments

This is a tricky question. It would be really annoying to add such clauses to every time we parse a parameter. On the other hand, the error messages could be clearer. Ideally, it would be great to do such programatically.

I know this is closed, but I am still pretty new to Elixir and I just got bit by this. This GitHub issue itself + Google was what helped me figure it out, because I was not explicitly passing a string but was passing in context.test, and it was not obvious that this was the problem.

I mention this because there have been so many awesome error messages so far with Elixir that it has really helped overcome the lack of intellisense/type inference that I am used with with tooling in other languages (I am a continuing convert from the Windows world). So, yes, I would say it would get annoying for individual messages for all parsing errors, absolutely!...But Elixir's documentation has been so superior in almost all regards and is one of its shining qualities :heart:, so this would have been a great error message tweak for newbs like me! :wink:

Thank you @bill-mybiz! @TattdCodeMonkey looking back I may have closed this a bit too hastily, sorry about that. Since this is a common case, let's definitely improve the error message, both on start_link and whereis.

Since we should likely do this for GenEvent and Supervisor as well, should we abstract this somewhere @josevalim?

@alecspopa I think we're missing such error only in Agent, correct?

Doesn't Agent use GenServer?

Whoops, it does, I'm already getting tired today 馃槢 Sorry!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jakubpawlowicz picture jakubpawlowicz  路  32Comments

wojtekmach picture wojtekmach  路  34Comments

josevalim picture josevalim  路  30Comments

josevalim picture josevalim  路  41Comments

josevalim picture josevalim  路  27Comments