mike_bianco

mike_bianco

Hello! I’ve been super impressed with the community here on the forum. Thanks for the help everyone has provided thus far!

I just finished my first side project in Elixir and there are a couple of things I’m missing from ruby-land, and some minor annoyances I’ve run into. I’m guessing there are extensions or tweaks I can make to eliminate most of these. I’d appreciate any insight—thank you!

Here’s the list of questions & missing tooling I’ve run into:

  1. Automatically open up a REPL when an exception is thrown. In ruby, this is done via pry-rescue. Super helpful for quickly diving into the exact context where the error occurs.
  2. In Phoenix, it would be amazing if the debugging plug (which displays a page when an exception is thrown) displays the variables bound in a specific scope so I can reproduce & fix errors quickly. (It would be even better if a REPL could be opened and interacted with on the exception page. better-errors does this in ruby.)
  3. iex -S mix phx.server feels weird. It would feel a bit nicer if there was a mix phx.console which setup IEx for you.
  4. Allow? [Yn] is really annoying when I’m debugging a piece of code. It would be great if you could auto-accept require IEx; IEx.pry requests.
  5. In a debugging session, I couldn’t figure out how to navigate up and down the call stack. Is there something like pry-nav available?
  6. Scan dependencies for security issues. In ruby, this is done via bundler-audit.
  7. I couldn’t find a VS Code extension with phoenix* snippets. Is there a way to autogenerate snippets automatically from installed hex packages?

Showing Posts 1 to 10

joaquinalcerro

joaquinalcerro

Cool.

Take a look at this presentation where Luke explains some debugging techniques:

It helped me hope it does the same for you.

hauleth

hauleth

Not possible as in most cases the failed process do not exist (unhandled exceptions will kill current process), so there is no “context” you can attach to.

As well I doubt that it would be possible, as Erlang do not provide anything like Kernel#local_variables in Ruby. Also as it was said earlier - process is probably dead when the error handling take place, so there is no “context”. Oh, and by the way, as Elixir compiles to Erlang code, and Erlang allows only one assignment per variable name (SSA-like) the “Elixir variables” will have non-meaningful names in Erlang code.

There was mix console but it was removed. I do not know what was the rationale. But if you do not like it, then you can always create custom command or alias (within Mix) or shell alias.

There is Sobelow, but I do not know if this audit the dependencies. For tool that checks deps for security issues we would need centralised log of such issues, AFAIK there is none, and AFAIK Elixir didn’t had any CVE assigned yet.

How would that even work? Really, I cannot imagine.

LostKobrakai

LostKobrakai

There’s Kernel.binding/1: Kernel — Elixir v1.20.2

hauleth

hauleth

Unfortunately it is macro, so it will not work in exception handling.

OvermindDL1

OvermindDL1

Huh?

iex(1)> a = 42
42
iex(2)> try do 
...(2)>   throw :ack
...(2)> catch v ->
...(2)>   b = 6.28
...(2)>   IO.inspect(binding(), label: :Bindings)
...(2)> end
Bindings: [a: 42, b: 6.28, v: :ack]
[a: 42, b: 6.28, v: :ack]

If a binding ‘can’ be used in the local scope, then binding() will show it, it just compiles to a keyword list of bindings names to the bindings themselves, like [a: a, b: b, v: v]. Is there a case where it will not show a binding that ‘can’ in fact be accessed in the local scope?!

mike_bianco

mike_bianco OP

Thanks for this tip! Do you happen to remember what version this was in? I spot checked a couple of versions through 1.3 and didn’t see anything.

Ah! Interesting. Is it possible to retrieve a context for the binding call from System.stacktrace? If so, then we could plug it (ha! no pun intended!) into the Plug.Debugger to retrieve bindings for each level of the stack trace. The issue here is the bindings for Plug.Debugger won’t be helpful, we need bindings up the stack.

OvermindDL1

OvermindDL1

That information is already available at compile time via macro’s, so a macro can already access that information.

Hmm?

hauleth

hauleth

Yeah, but in general you cannot do:

def call(conn, opts) do
  a = 10
  throw :ack
end

try do
  call(conn, [])
catch
  v ->
    IO.inspect(binding(__STACKTRACE__)) # or other magic there
end

And get value of a. And that is what would be needed for what @mike_bianco want.

OvermindDL1

OvermindDL1

What a? There is no a in scope at the point binding is called? Is there supposed to be an a?

michallepicki

michallepicki

In debuggers for many languages it’s possible to “break on exception” where the debugger would attach immediately where an exception happened (not anywhere higher up the stack). This is similar to what Ruby’s pry-rescue does and this is what @mike_bianco wants.

I’m not sure if it’s doable on the BEAM but I’d love to see something like that (preferably using the :debugger instead of IEx but I know many people would prefer the pry)

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews