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

marcandre
Compilation time for our project degraded from ~26 seconds to ~32 seconds (~23% slower) :disappointed_face:. Did anyone else compare com...
New
garrison
The Elixir ecosystem is one of our biggest strengths, and the BEAM really lends itself to native implementations (e.g. Cachex over Redis,...
New
Sergiusz
Hello everyone, I don’t know if my post is appropriate. If it isn’t, you can delete it. After a year of designing and defining the requ...
New
tcoopman
Yesterday I watched OpenTelemetry: From Desire to Dashboard and it triggered me to take a new look at telemetry in Elixir. But I don’t k...
New
stevensonmt
Has anyone else ever wanted to merge two maps, but have the resulting map only include keys common to both maps? I think of it as analogo...
New
bartblast
Some great comments in the home page thread shifted toward what you’d like to see in Hologram’s future, particularly standalone mode. I’v...
New
michallepicki
Hello! To save some time when switching projects or development machines, I glued together an asdf plugin that uses Erlang precompiled b...
New
karlosmid
The |> operator appears in many languages, mostly in the functional world. F# has essentially the exact same operator, as does OCaml. ...
New
AstonJ
Posting this as a separate thread as I’m sure lots of people will be curious - what will the (or the intended) differences be and when mi...
New
matreyes
I haven’t seen this paper being discussed by the community, but I think this makes Elixir more relevant than ever. TLDR; The paper...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement