explaingit

bettererrors/better_errors

6,874RubyAudience · developerComplexity · 2/5Setup · easy

TLDR

A Ruby gem that replaces the plain Rails error page with a rich debugger showing highlighted source code, local variable values, and a live interactive console.

Mindmap

mindmap
  root((better_errors))
    What it does
      Rich error pages
      Syntax highlighted code
      Variable inspector
      Live Ruby console
    Setup
      Add gem to dev group
      Rack middleware option
      Set editor env var
    Limitations
      Dev only never prod
      Single worker needed
      Private data exposed
    Frameworks
      Rails
      Sinatra
      Any Rack app
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

See the exact variable values and call stack at the moment your Rails app crashes, without adding print statements.

USE CASE 2

Run arbitrary Ruby commands in the context of a crashed request to probe what went wrong.

USE CASE 3

Click a file reference on the error page to jump directly to that line in your code editor.

USE CASE 4

Add it to any Rack-based Ruby app such as Sinatra as a middleware layer for better error output.

Tech stack

RubyRackRails

Getting it running

Difficulty · easy Time to first run · 5min

Must never be used in production, the live console exposes full application state and may reveal private data.

No license information was mentioned in the explanation.

In plain English

Better Errors is a Ruby library that replaces the default error page shown in Rails applications during development with a significantly more informative one. When your app crashes, instead of seeing a basic stack trace, you get syntax-highlighted source code for each frame in the call stack, the values of local and instance variables at the point of failure, and a live console where you can type Ruby commands directly in the context of the error. The library works with any Ruby web app that uses the Rack interface, which is the standard foundation most Ruby web frameworks sit on, not just Rails. For Rails apps, adding the gem to your development dependencies is all that is needed. For other frameworks, you add it manually as a middleware layer, which is a component that sits in the request-handling pipeline. One useful feature is click-to-open: the error page shows a link next to each file reference that opens that file directly in your code editor at the right line. This requires setting an environment variable to tell the library which editor you use. The library should only ever be used in the development environment on your own machine. The live console exposes the full state of your running application, and the error page may contain private information from your codebase or data. The README explicitly warns against running it in production or on any publicly accessible server. A known limitation is that the live console stores session state in a single server process. If you are running a development server with multiple worker processes, a follow-up request from the error page may land on a different worker that has no memory of the original crash context, resulting in a session expiry message. The fix is to configure development to use only one worker process.

Copy-paste prompts

Prompt 1
I added the better_errors gem to my Rails app's development group but the old error page still shows. Walk me through how to verify it is installed correctly and troubleshoot why it might not be activating.
Prompt 2
How do I configure better_errors to open files in VS Code when I click a line reference on the error page?
Prompt 3
I am running Rails development with multiple Puma workers and better_errors shows a session expired message on the console. What is causing this and how do I fix it?
Prompt 4
Show me how to add better_errors as a middleware to a Sinatra app that does not use Rails.
Open on GitHub → Explain another repo

← bettererrors on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.