elixir-lang / elixir-lang.github.com

Website for Elixir
elixir-lang.org
354 stars 822 forks source link

File.read(file) receives a PID instead of a path #1626

Closed dpreston closed 2 years ago

dpreston commented 2 years ago
{:ok, file} = File.open("hello", [:write])

case File.read(file) do
  {:ok, body}      -> # do something with the `body`
  {:error, reason} -> # handle the error caused by `reason`
end

If this example is used verbatim, you will get the error

** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1
    The following arguments were given to IO.chardata_to_string/1:
        # 1
        #PID<0.117.0>
    Attempted function clauses (showing 2 out of 2):
        def chardata_to_string(string) when is_binary(string)
        def chardata_to_string(list) when is_list(list)
    (elixir 1.13.4) lib/io.ex:627: IO.chardata_to_string/1
    (elixir 1.13.4) lib/file.ex:341: File.read/1

file should be a path, not the PID set earlier in the guide

dpreston commented 2 years ago

Urgh, accidently added the "try-catch-and-rescue.markdown" file as well to this patch which corrects an error where what_happened/0 should not be defined but actually has been

josevalim commented 2 years ago

:green_heart: :blue_heart: :purple_heart: :yellow_heart: :heart: