Embedding interactive IEx shell in debugging page shown for development builds

I’m exploring ways to embed underthehood into the debugging page used when debug_errors: true is set on the endpoint. This package provides a LiveView component presenting a fully-functional Iex session into the VM, enabling people to go spelunking around their application code in case anything goes wrong. I suspect this might come in handy when debugging.

To avoid pulling in unnecessary dependencies, my plan was to first contribute a PR which adjusts Phoenix.Endpoint.RenderErrors.__debug_banner__/5 such that it somehow considers “hooks” (e.g. a list of MFA tuples) provided via the configuration when rendering markup. Any hooks would then get invoked, contributing additional markup.

I could then go ahead and create a phoenix_live_debug_terminal package or the like which depends on underthehood and implements a hook embedding the terminal component into the error page. Users would get the interactive shell (and a LiveView dependency) simply by depending on phoenix_live_debug_terminal and configuring their endpoint(s) like

config :my_app, MyApp.Endpoint,
  debug_page_hooks: {Phoenix.LiveDebugTerminal, :render, []}

…such that when rendering the debug page, a nice little terminal is embedded.

Before going ahead, I wanted to reach out and clarify:

  • Does having an interactive IEx shell in the debug view seem like a useful feature?
  • Is the approach of making Phoenix.Endpoint.RenderErrors.__debug_banner__/5 respect hooks (specified via MFA tuples) a good way about enabling users to extend the debug page?

Any feedback is much appreciated. :blush:

6 Likes

This sounds like a great idea to me! I made great use of a similar functionality for Rails. And I like the architecture you have proposed.

1 Like

Thanks for the encouraging feedback!

I now built a first version of this module - say hello to phoenix_live_debug_console. :slight_smile:

The project page has a little video showing it in practice.

Caveat: at this point, a custom Phoenix build is required with PR 4938 applied. I hope I can get this in for one of the next Phoenix releases. Fingers crossed!

3 Likes