Quantcast
Channel: 一言多いプログラマーの独り言
Viewing all articles
Browse latest Browse all 846

Elixirでファイルの読み込み(File.read)「(ArgumentError)」になる場合

$
0
0
Elixirでファイルの読み込み(File.read)です。なんで、argument errorになるんだろうと思いましたが、File.readFile.read!では、戻り値が違うんですね。目から鱗が落ちました。


$ iex -S mix

iex(1)> file_read = File.read "priv/contents/filename.md"
{:ok, "### Hello world!"}

iex(2)> marked = Markdown.to_html file_read
** (ArgumentError) argument error
Markdown.to_html({:ok, "### Hello world!"}, [])
iex(2)> {:ok, file_read} = File.read "priv/contents/filename.md"
{:ok, "### Hello world!"}

iex(3)> marked = Markdown.to_html file_read
"<h3>Hello world!</h3>\n"

iex(4)> file_read = File.read! "priv/contents/test.md"
"### Hello world!"

iex(5)> marked = Markdown.to_html file_read
"<h3>Hello world!</h3>\n"

参考サイト
Cowboy Tutorial Part 2: Creating Flat File Blog(ElixirDoseさん)
File(Elixir)
ArgumentError(Elixir)
「Phoenix」フレームワークでMarkdown(Earmark)

Viewing all articles
Browse latest Browse all 846

Trending Articles