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
IO.inspect returns its argument so your route function passes the map along to… whatever code is actually calling IO.puts (still not shown
) 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
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
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…
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








