lc0815

lc0815

String.char error - (Protocol.UndefinedError) protocol String.Chars not implemented

this code is from a course from pragmaticstudio

def parse(request) do
#TODO: parse the request string into a map:
first_line = request |> String.split("\n") |> List.first
[method, path, _] = String.split(first_line, " ")
%{ method: method, path: path, resp_body: “”}
end

this line:
%{ method: method, path: path, resp_body: “”}
gives me the error:

== Compilation error in file lib/servy/handler.ex ==
** (Protocol.UndefinedError) protocol String.Chars not implemented for %{method: "GET", path: "/wildthings", resp_body: ""} of type Map
    (elixir 1.12.3) lib/string/chars.ex:3: String.Chars.impl_for!/1
    (elixir 1.12.3) lib/string/chars.ex:22: String.Chars.to_string/1
    (elixir 1.12.3) lib/io.ex:712: IO.puts/2
    (elixir 1.12.3) lib/kernel/parallel_compiler.ex:319: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7

but the code does not give an error on their screen.

the full error message:

(Protocol.UndefinedError) protocol String.Chars not implemented for %{method: "GET", path: "/wildthings", resp_body: ""} of type Map

Most Liked

al2o3cr

al2o3cr

IO.inspect returns its argument so your route function passes the map along to… whatever code is actually calling IO.puts (still not shown :frowning: ) and you get the same error.

Commenting out the whole IO.inspect line will make route return nil, which IO.puts is fine with (it prints a single newline).

al2o3cr

al2o3cr

The error appears to be caused by passing the result of parse to IO.puts; can you show that code?

FWIW, IO.inspect is usually a better tool for printing things mid-calculation, as it can show maps/tuples/PIDs/etc that don’t work with IO.puts.

lc0815

lc0815

thanks for all of your comments, the issue were some hidden chars on the file, I created a new file and re-typed the code and the problem went away… need a new keyboard LoL, got to blame it on something…
anywho: alls ok now…

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement