Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"protocol String.Chars not implemented " even when I'm using "inspect"

I have an action:

def my_action(conn, params) do
  # ..............

  Logger.info("test: params #{IO.inspect(params)};\r\n\r\n")

This causes an exception:

  ** (Protocol.UndefinedError) protocol String.Chars not implemented for %{"key1" => "var1", "key2" => "var2", # ........}. 
      This protocol is implemented for: Atom, BitString.................

I comprehend what it means, but I can't understand why it's caused? I'm using "inspect". What should I use instead to fix it?

like image 403
user10000037 Avatar asked Jun 27 '18 12:06

user10000037


1 Answers

IO.inspect prints the value and then returns the value. Other than printing the value, it's the same as writing

"test: params #{params};\r\n\r\n"

What you need here is Kernel.inspect or simply inspect:

Logger.info("test: params #{inspect(params)};\r\n\r\n")
like image 101
Dogbert Avatar answered Nov 09 '22 19:11

Dogbert