Euphorichuman
I’ve been doing the Get Started elixir. I’m currently going part 9 of MIX AND OTP, but I am having an error with the Doctests that I cannot fix:
I have this command parser file just as the tutorial tells me:
defmodule KVServer.Command do
@doc ~S"""
Parses the given `line` into a command.
## Examples
iex> KVServer.Command.parse "CREATE shopping\r\n"
{:ok, {:create, "shopping"}}
iex> KVServer.Command.parse "CREATE shopping \r\n"
{:ok, {:create, "shopping"}}
iex> KVServer.Command.parse "PUT shopping milk 1\r\n"
{:ok, {:put, "shopping", "milk", "1"}}
iex> KVServer.Command.parse "GET shopping milk\r\n"
{:ok, {:get, "shopping", "milk"}}
iex> KVServer.Command.parse "DELETE shopping eggs\r\n"
{:ok, {:delete, "shopping", "eggs"}}
Unknown commands or commands with the wrong number of
arguments return an error:
iex> KVServer.Command.parse "UNKNOWN shopping eggs\r\n"
{:error, :unknown_command}
iex> KVServer.Command.parse "GET shopping\r\n"
{:error, :unknown_command}
"""
def parse(line) do
case String.split(line) do
["CREATE", bucket] -> {:ok, {:create, bucket}}
["GET", bucket, key] -> {:ok, {:get, bucket, key}}
["PUT", bucket, key, value] -> {:ok, {:put, bucket, key, value}}
["DELETE", bucket, key] -> {:ok, {:delete, bucket, key}}
_ -> {:error, :unknown_command}
end
end
@doc """
Runs the given command.
"""
def run(command)
def run({:create, bucket}) do
MixTest.Registry.create(MixTest.Registry, bucket)
{:ok, "OK\r\n"}
end
def run({:get, bucket, key}) do
lookup(bucket, fn pid ->
value = MixTest.Bucket.get(pid, key)
{:ok, "#{value}\r\nOK\r\n"}
end)
end
def run({:put, bucket, key, value}) do
lookup(bucket, fn pid ->
MixTest.Bucket.put(pid, key, value)
{:ok, "OK\r\n"}
end)
end
def run({:delete, bucket, key}) do
lookup(bucket, fn pid ->
MixTest.Bucket.delete(pid, key)
{:ok, "OK\r\n"}
end)
end
defp lookup(bucket, callback) do
case MixTest.Registry.lookup(MixTest.Registry, bucket) do
{:ok, pid} -> callback.(pid)
:error -> {:error, :not_found}
end
end
end
Note: MixTest is my module from another application that is under umbrella (KV module in the tutorial).
When I try to run the tests, all the doc tests fail, apparently because it does not recognize a blank space or something that I do not understand.
These are the messages that the console shows me when I run the mix test command:
==> kv_server
1) doctest KVServer.Command.parse/1 (2) (KVServer.CommandTest)
apps/kv_server/test/kv_server/command_test.exs:3
" (column 49, code point U+000D)t: (SyntaxError) lib/kv_server/command.ex:10:49: unexpected token: "
doctest:
iex> KVServer.Command.parse "CREATE shopping \r\n"
{:ok, {:create, "shopping"}}
stacktrace:
lib/kv_server/command.ex:10: KVServer.Command (module)
2) doctest KVServer.Command.parse/1 (3) (KVServer.CommandTest)
apps/kv_server/test/kv_server/command_test.exs:3
" (column 50, code point U+000D)t: (SyntaxError) lib/kv_server/command.ex:13:50: unexpected token: "
doctest:
iex> KVServer.Command.parse "PUT shopping milk 1\r\n"
{:ok, {:put, "shopping", "milk", "1"}}
stacktrace:
lib/kv_server/command.ex:13: KVServer.Command (module)
3) doctest KVServer.Command.parse/1 (4) (KVServer.CommandTest)
apps/kv_server/test/kv_server/command_test.exs:3
" (column 48, code point U+000D)t: (SyntaxError) lib/kv_server/command.ex:16:48: unexpected token: "
doctest:
iex> KVServer.Command.parse "GET shopping milk\r\n"
{:ok, {:get, "shopping", "milk"}}
stacktrace:
lib/kv_server/command.ex:16: KVServer.Command (module)
4) doctest KVServer.Command.parse/1 (6) (KVServer.CommandTest)
apps/kv_server/test/kv_server/command_test.exs:3
" (column 52, code point U+000D)t: (SyntaxError) lib/kv_server/command.ex:25:52: unexpected token: "
doctest:
iex> KVServer.Command.parse "UNKNOWN shopping eggs\r\n"
{:error, :unknown_command}
stacktrace:
lib/kv_server/command.ex:25: KVServer.Command (module)
5) doctest KVServer.Command.parse/1 (7) (KVServer.CommandTest)
apps/kv_server/test/kv_server/command_test.exs:3
" (column 43, code point U+000D)t: (SyntaxError) lib/kv_server/command.ex:28:43: unexpected token: "
doctest:
iex> KVServer.Command.parse "GET shopping\r\n"
{:error, :unknown_command}
stacktrace:
lib/kv_server/command.ex:28: KVServer.Command (module)
6) doctest KVServer.Command.parse/1 (1) (KVServer.CommandTest)
apps/kv_server/test/kv_server/command_test.exs:3
" (column 46, code point U+000D)t: (SyntaxError) lib/kv_server/command.ex:7:46: unexpected token: "
doctest:
iex> KVServer.Command.parse "CREATE shopping\r\n"
{:ok, {:create, "shopping"}}
stacktrace:
lib/kv_server/command.ex:7: KVServer.Command (module)
7) doctest KVServer.Command.parse/1 (5) (KVServer.CommandTest)
apps/kv_server/test/kv_server/command_test.exs:3
" (column 51, code point U+000D)t: (SyntaxError) lib/kv_server/command.ex:19:51: unexpected token: "
doctest:
iex> KVServer.Command.parse "DELETE shopping eggs\r\n"
{:ok, {:delete, "shopping", "eggs"}}
stacktrace:
lib/kv_server/command.ex:19: KVServer.Command (module)
.
Finished in 0.1 seconds (0.1s async, 0.00s sync)
7 doctests, 1 test, 7 failures
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
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
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #iex
- #elixirconf-us
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
gpopides
i don’t know the tutorial but i can see that the difference between rest examples are that
contains a space between shopping and \r\n.
What happens if you remove that space?
Euphorichuman
Removing this space does not solve the problem.
Tutorial btw: https://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html
lucaong
I am on my phone now, so I cannot verify, but it looks like a problem with escaping of
\r\n. Indeed it says that the unicode code point where it breaks is the hexadecimal 000D, which is the carriage return.What happen if you escape the backslash with another backslash like
\\r\\n?josevalim
This is an Elixir bug that has been fixed in the upcoming v1.13: doctest raises syntaxerror: unexpected token · Issue #11291 · elixir-lang/elixir · GitHub
A temporary solution for now is to configure your editor to use Unix/DOS style newlines.