Plug.Debugger
A module (not a plug) for debugging in development.
The module is commonly used within a Plug.Builder
or a Plug.Router
and it wraps the call/2
function:
defmodule MyApp do
use Plug.Builder
if Mix.env == :dev do
use Plug.Debugger, otp_app: :my_app
end
plug :boom
def boom(conn, _) do
# Error raised here will be caught and displayed in a debug
# page complete with a stacktrace and other helpful info
raise "oops"
end
end
Notice Plug.Debugger
does not catch errors, as errors should still
propagate so the Elixir process finishes with the proper reason.
This module does not perform any logging either, as all logging is done
by the web server handler.
PLUG_EDITOR
If a PLUGEDITOR environment variable is set, Plug.Debugger
is going
to use it to generate links to your text editor. The variable should be
set with FILE and _LINE placeholders which will be correctly
replaced, for example:
txmt://open/?url=file://__FILE__&line=__LINE__
Manual usage
One can also manually use Plug.Debugger
by invoking the wrap/3
function directly.
Summary
get_snippet(file, line) | |
template(assigns) | |
wrap(conn, opts, fun) | Wraps a given function and renders a nice error page in case the function fails |