I had a very large module (for my experience) with around 2k loc. I broke it down for organisational purposes, although I’m just “importing” these new modules into a main one. Now whenever I have an error that occurs in one of the modules being used I get the stack trace with the line where the module is imported, along with the function name and arity.
** (ArgumentError) could not put/update key nil on a nil value
(elixir) lib/access.ex:371: Access.get_and_update/3
(elixir) lib/kernel.ex:1880: Kernel.put_in/3
(AetherWars) lib/aetherwars/duels/duels_processor.ex:12: AetherWars.Duels.Processor.decide_next_player/1
(AetherWars) lib/aetherwars/duels/duels_processor.ex:11: AetherWars.Duels.Processor.pop_stack/4
(AetherWars) lib/aetherwars/duels/duels_processor.ex:22: AetherWars.Duels.Processor.entry_point/4
(AetherWars) web/channels/duel_channel.ex:25: AetherWars.DuelChannel.handle_in/3
(phoenix) lib/phoenix/channel/server.ex:244: anonymous fn/4 in Phoenix.Channel.Server.handle_info/2
(AetherWars) lib/aetherwars/endpoint.ex:1: AetherWars.Endpoint.instrument/4
(stdlib) gen_server.erl:616: :gen_server.try_dispatch/4
(stdlib) gen_server.erl:686: :gen_server.handle_msg/6
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Sometimes this is all I need, but other times I have several different functions with the same arity pattern-matching on the head. Is there any way to be able to see in which line of the original module that has been use
d it occurs? (I guess since use
when compiled basically places the code on the module calling it, it won’t be straightforward but perhaps there’s some easy work-around?)
You can see it becomes a bit problematic:
defmodule AetherWars.Duels.Processor do
use AetherWars.Duels.Create
use AetherWars.Duels.Utils
use AetherWars.Duels.Payment
use AetherWars.Duels.Legal
use AetherWars.Duels.Messages
use AetherWars.Duels.Strike
use AetherWars.Duels.Guard
use AetherWars.Duels.Stack
use AetherWars.Duels.Turn
use AetherWars.Duels.Manipulation
use AetherWars.Duels.Battle
alias AetherWars.Duels.Monitor
...
end
Any solution? Thanks