cronokirby / alchemy

A discord library for Elixir
MIT License
151 stars 34 forks source link

bad map error when working with alchemy guilds cache? #53

Open purei opened 6 years ago

purei commented 6 years ago

The bot was logged in to Discord, but user commands were erroring out with this error. Restarting the app fixed things.

11:57:22.183 [info]  GenStage consumer #PID<0.341.0> is stopping after receiving cancel from producer #PID<0.340.0> with reason: {{:badmap, nil},
 [{:maps, :values, [nil], []},
  {Alchemy.Cache.Guilds, :"-de_index/1-fun-0-", 1,
   [file: 'lib/Cache/guilds.ex', line: 79]},
  {Map, :get_and_update, 3, [file: 'lib/map.ex', line: 766]},
  {Alchemy.Cache.Guilds, :"-de_index/1-fun-1-", 2,
   [file: 'lib/Cache/guilds.ex', line: 79]},
  {Enum, :"-reduce/3-lists^foldl/2-0-", 3, [file: 'lib/enum.ex', line: 1811]},
  {Alchemy.Discord.Events, :handle, 2,
   [file: 'lib/Discord/events.ex', line: 48]},
  {Enum, :"-map/2-lists^map/1-0-", 2, [file: 'lib/enum.ex', line: 1255]},
  {Alchemy.EventStage.Cacher, :handle_events, 3,
   [file: 'lib/EventStage/cacher.ex', line: 27]}]}

11:57:22.188 [error] GenServer #PID<0.341.0> terminating
** (BadMapError) expected a map, got: nil
    (stdlib) :maps.values(nil)
    (alchemy) lib/Cache/guilds.ex:79: anonymous fn/1 in Alchemy.Cache.Guilds.de_index/1
    (elixir) lib/map.ex:766: Map.get_and_update/3
    (alchemy) lib/Cache/guilds.ex:79: anonymous fn/2 in Alchemy.Cache.Guilds.de_index/1
    (elixir) lib/enum.ex:1811: Enum."-reduce/3-lists^foldl/2-0-"/3
    (alchemy) lib/Discord/events.ex:48: Alchemy.Discord.Events.handle/2
    (elixir) lib/enum.ex:1255: Enum."-map/2-lists^map/1-0-"/2
    (alchemy) lib/EventStage/cacher.ex:27: Alchemy.EventStage.Cacher.handle_events/3
Last message: {:DOWN, #Reference<0.3146950353.1864630273.4610>, :process, #PID<0.340.0>, {{:badmap, nil}, [{:maps, :values, [nil], []}, {Alchemy.Cache.Guilds, :"-de_index/1-fun-0-", 1, [file: 'lib/Cache/guilds.ex', line: 79]}, {Map, :get_and_update, 3, [file: 'lib/map.ex', line: 766]}, {Alchemy.Cache.Guilds, :"-de_index/1-fun-1-", 2, [file: 'lib/Cache/guilds.ex', line: 79]}, {Enum, :"-reduce/3-lists^foldl/2-0-", 3, [file: 'lib/enum.ex', line: 1811]}, {Alchemy.Discord.Events, :handle, 2, [file: 'lib/Discord/events.ex', line: 48]}, {Enum, :"-map/2-lists^map/1-0-", 2, [file: 'lib/enum.ex', line: 1255]}, {Alchemy.EventStage.Cacher, :handle_events, 3, [file: 'lib/EventStage/cacher.ex', line: 27]}]}}
State: %ConsumerSupervisor{args: :ok, children: %{}, max_restarts: 3, max_seconds: 5, mod: Alchemy.EventStage.Tasker, name: {#PID<0.341.0>, Alchemy.EventStage.Tasker}, producers: %{#Reference<0.3146950353.1864630273.4609> => {{#PID<0.339.0>, #Reference<0.3146950353.1864630273.4609>}, 0, 2, 500, 1000}}, restarting: 0, restarts: [], strategy: :one_for_one, template: {Alchemy.EventStage.Tasker.Runner, {Alchemy.EventStage.Tasker.Runner, :start_link, []}, :temporary, 5000, :worker, [Alchemy.EventStage.Tasker.Runner]}}
OvermindDL1 commented 6 years ago

I keep getting this as well, it happens pretty often, upon which then I have to manually reboot (why is that getting a nil, why is it not supervised so it restarts?).

10:38:35.996 [error] GenServer :"Elixir.Alchemy.EventStage.Cacher.2" terminating
** (BadMapError) expected a map, got: nil
    (stdlib) :maps.values(nil)
    (alchemy) lib/Cache/guilds.ex:79: anonymous fn/1 in Alchemy.Cache.Guilds.de_index/1
    (elixir) lib/map.ex:766: Map.get_and_update/3
    (alchemy) lib/Cache/guilds.ex:79: anonymous fn/2 in Alchemy.Cache.Guilds.de_index/1
    (elixir) lib/enum.ex:1826: Enum."-reduce/3-lists^foldl/2-0-"/3
    (alchemy) lib/Discord/events.ex:48: Alchemy.Discord.Events.handle/2
    (elixir) lib/enum.ex:1270: Enum."-map/2-lists^map/1-0-"/2
    (alchemy) lib/EventStage/cacher.ex:27: Alchemy.EventStage.Cacher.handle_events/3
Last message: {:"$gen_consumer", {#PID<0.336.0>, #Reference<0.3966592715.874250244.217763>}, [{"GUILD_UPDATE", %{"afk_channel_id" => "...
...
OvermindDL1 commented 6 years ago

Any thoughts as to cause?

cronokirby commented 6 years ago

Odd that it doesn't restart, considering that it is supervised...

OvermindDL1 commented 6 years ago

Getting this quite often as well, if it is related, or should it be a new bug report?

(BadMapError) expected a map, got: nil
    (stdlib) :maps.values(nil)
    (alchemy) lib/cache.ex:189: anonymous fn/1 in Alchemy.Cache.search/2
    (elixir) lib/stream.ex:444: anonymous fn/3 in Stream.flat_map/2
    (elixir) lib/stream.ex:867: Stream.do_transform_user/6
    (elixir) lib/stream.ex:1536: Enumerable.Stream.do_each/4