elixir and erlang stacktraces
Erlang and Elixir stacktraces eats the last frame because of super TCO optimizations
Reproduced able with
defmodule Demo do
def start do
perform(__MODULE__, :target, [])
end
def perform(module, function, args) do
{_, stacktrace} = Process.info(self(), :current_stacktrace)
IO.inspect(stacktrace, label: "Stack trace in 'perform'")
IO.inspect(self(), label: "PERFORM PID")
apply(module, function, args)
end
def target do
{_, stacktrace} = Process.info(self(), :current_stacktrace)
IO.inspect(self(), label: "TARGET PID")
IO.inspect(stacktrace, label: "Stack trace in 'target'")
end
end
Demo.start()
If you apply on the last line it’ll eat the stacktrace