Oliver

Oliver

Two musings about stacktrace functionality

Currently I have in my project two ways to make a stack trace:

One function to be used in try-blocks piping __STACKTRACE__ into Exception.format_stacktrace/1 and then into the Logger.

And one that calls uses Process.info/2 and then formats that with Exception.format_stacktrace_entry/1 similar to Exception.format_stacktrace/1 without arguments.

The reasoning is this: The implementation of Exception.format_stacktrace/1 is like this:

      if trace do
        trace
      else
        case Process.info(self(), :current_stacktrace) do
          {:current_stacktrace, t} -> Enum.drop(t, 3)
        end
      end

In all cases where I tried to use it, it shaved off the immediate caller (like the module used for callbacks in a GenServer) and left me with “the uninteresting part” (the stack trace elements pertaining to :gen_server, for example). Might it not be better to do a tl(t) here? (Then it just removes the entry for Process.info/2.)

The other thing is about the __STACKTRACE__ special form. It is not usable outside catch/rescue. But wouldn’t it be handier if it just returned nil in all other contexts?

Then you could always pipe it into Exception.format_stacktrace/1 and reuse the same code everywhere.

I admit in my case it would be a minor improvement, but currently the user has to always decide which of my two stack trace functions to call.

First Post!

Oliver

Oliver

Ah, sorry, I just redid my code and realized that one of these two was my bad:

I called Exception.format_stacktrace/1 from inside a macro’s quote block which changes the stacktrace. Now that I converted my code into a function I see why the first three entries were removed.

Where Next?

Popular in Discussions Top

pillaiindu
In django there is a cache framework backed by memcached. Rails also puts a lot of emphasis on caching, and even the idea of russian-doll...
New
MarioFlach
Hello, I want to share a project I’ve been working on for a while: https://github.com/almightycouch/gitgud Background Some time ago I ...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
chuck
Let me start by stating an assumption: Phoenix is a great approach to building REST APIs. There are many reasons for this, but I will ass...
New
Fl4m3Ph03n1x
Background A few days ago I was listening to The future of Elixir from Elixir Talks, with Dave Thomas (@pragdave ) and Brian Mitchell. I...
New
owaisqayum
I have a sample string sentence = "Hello, world ... 123 *** ^%&*())^% %%:>" From this string, I want to only keep the integers, ...
New
nunobernardes99
Hi there Elixir friends :vulcan_salute: In a recent task I was on, I needed to check in two dates which of them is the maximum and which...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement