From 41d8b85c1169293f5747e923420473691431178a Mon Sep 17 00:00:00 2001 From: Olivier Lacan Date: Sun, 12 Nov 2023 17:19:47 -0800 Subject: [PATCH] Debugging documentation for hanami server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's a fairly important part of getting to know a new framework, and I couldn't find any mention of `binding.irb` or `binding.pry` in the guides. There's currently no open issue for this, so apologies for the unsolicited PR. 😅 --- content/v2.0/cli-commands/commands.md | 23 +++++++++++++++++++++++ content/v2.1/cli-commands/commands.md | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/content/v2.0/cli-commands/commands.md b/content/v2.0/cli-commands/commands.md index 23600cad..919cf41b 100644 --- a/content/v2.0/cli-commands/commands.md +++ b/content/v2.0/cli-commands/commands.md @@ -169,6 +169,29 @@ This server is for local development only. In production, use the following to s $ bundle exec puma -C config/puma.rb ``` +### Debugging + +Since Hanami uses code reloading by default, placing a `binding.irb` +call in your code won't open an IRB debugging session in the server +logs as you might expect. + +Within your own application code, you call `raise` to trigger the +[hanami-webconsole][wc] interactive error page and interact with +the execution context in an IRB-like REPL. + +[webconsole]: https://github.com/hanami/webconsole + +However, this will not work with third-party code like gems. In that +case you can disable code reloading by starting the server with: + +```shell +bundle exec hanami server --no-code-reloading +``` + +Calls to `binding.irb` (or `binding.pry` for Pry) should now +work, not only in your Hanami application code. The IRB debugging +console will open your shell wherever you started the Hanami server. + ## hanami version Prints the version of the installed hanami gem. diff --git a/content/v2.1/cli-commands/commands.md b/content/v2.1/cli-commands/commands.md index 898df557..c095ae4d 100644 --- a/content/v2.1/cli-commands/commands.md +++ b/content/v2.1/cli-commands/commands.md @@ -169,6 +169,29 @@ This server is for local development only. In production, use the following to s $ bundle exec puma -C config/puma.rb ``` +### Debugging + +Since Hanami uses code reloading by default, placing a `binding.irb` +call in your code won't open an IRB debugging session in the server +logs as you might expect. + +Within your own application code, you call `raise` to trigger the +[hanami-webconsole][wc] interactive error page and interact with +the execution context in an IRB-like REPL. + +[webconsole]: https://github.com/hanami/webconsole + +However, this will not work with third-party code like gems. In that +case you can disable code reloading by starting the server with: + +```shell +bundle exec hanami server --no-code-reloading +``` + +Calls to `binding.irb` (or `binding.pry` for Pry) should now +work, not only in your Hanami application code. The IRB debugging +console will open your shell wherever you started the Hanami server. + ## hanami version Prints the version of the installed hanami gem.