Oliver
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.
Trending in Discussions
Other Trending Topics
Chat & Discussions>Discussions
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #ai
- #iex
- #graphql
- #elixirconf-us
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Oliver
Ah, sorry, I just redid my code and realized that one of these two was my bad:
I called
Exception.format_stacktrace/1from 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.