cronokirby/alchemy

[bug] When Client.edit_member succeeds, a parsing error occurs

Closed this issue · 0 comments

Description
When Client.edit_member succeeds, the API returns an empty body. This is passed to the decoder in Alchemy.Discord.Api.handle_response/2 as an empty string, and this throws an error as it is parsed as JSON.

Test

defmodule AlchemyTest do
  use Application
  use Alchemy.Cogs

  alias Alchemy.Client
  alias Alchemy.Events

  defmodule Commands do
    use Alchemy.Cogs

    Cogs.def nick(name) do
      %{channel_id: channel_id, author: %{id: user_id}} = message
      {:ok, guild_id} = Alchemy.Cache.guild_id(channel_id)
      {:ok, _} = Client.edit_member(guild_id, user_id, nick: name)
      Cogs.say "Done"
    end
  end

  @spec start(any, any) :: {:ok, pid}
  def start(_type, _args) do
    run = Client.start(System.get_env("TOKEN"))
    use Commands
    run
  end
end

Expected Behaviour
Sending !nick david changes your nickname to "david" and then prints "Done".

Observed Behaviour
Nickname is successfully changed to "david", but then the process crashes with the following error:

21:02:17.077 [error] Task #PID<0.307.0> started from #PID<0.299.0> terminating
** (Poison.ParseError) Unexpected end of input at position 0
    lib/poison/parser.ex:357: Poison.Parser.value/3
    lib/poison/parser.ex:64: Poison.Parser.parse!/2
    (alchemy) lib/Discord/api.ex:97: anonymous fn/2 in Alchemy.Discord.Api.handle/2
    (alchemy) lib/Discord/api.ex:126: Alchemy.Discord.Api.handle_response/2
    (alchemy) lib/Discord/rate_manager.ex:37: Alchemy.Discord.RateManager.process_req/3
    (alchemy_test) lib/alchemy_test.ex:14: AlchemyTest.Commands.nick/2
    (elixir) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Function: &AlchemyTest.Commands.nick/2
...