better_errors ruby Rubygems

Better error page for Rails and other Rack apps

Better Errors

Better Errors replaces the standard Rails error page with a much better and more useful error page. It is also usable outside of Rails in any Rack app as Rack middleware.



  • Full stack trace

  • Source code inspection for all stack frames (with highlighting)

  • Local and instance variable inspection

  • Live REPL (read, eval, print loop) on every stack frame


Add this to your Gemfile:

group :development do
  gem "better_errors"

If you would like to use Better Errors’ advanced features (REPL, local/instance variable inspection, pretty stack frame names), you need to add the binding_of_caller gem by @banisterfiend to your Gemfile:

gem "binding_of_caller"

This is an optional dependency however, and Better Errors will work without it.


NOTE: It is critical you put better_errors in the development section. Do NOT run better_errors in production, or on Internet facing hosts.

Obviously, a REPL is not something you want to expose to the public. In addition, the other sensitive info might exist within full volume of information provided by Better Errors. To contain this, the default setup is to serve Ancient Errors to everyone but localhost (and this includes virtually remote hosts, such as a Vagrant box).

To poke selective holes in this security mechanism, you can add a line like this to your startup (for example, on Rails it would be config/environments/development.rb)

BetterErrors::Middleware.allow_ip! ENV['TRUSTED_IP'] if ENV['TRUSTED_IP']

# Then run rails like:
TRUSTED_IP= rails s

Note that it is actually implemented as a Set, so you can add more than one.

Tip: You can find your apparent IP by hitting the old error page’s “Show env dump” and looking at “REMOTE_ADDR”.


If you’re using Rails, there’s nothing else you need to do.

If you’re not using Rails, you need to insert BetterErrors::Middleware into your middleware stack, and optionally set BetterErrors.application_root if you’d like Better Errors to abbreviate filenames within your application.

Here’s an example using Sinatra:

require "sinatra"
require "better_errors"

configure :development do
  use BetterErrors::Middleware
  BetterErrors.application_root = File.expand_path("..", __FILE__)

get "/" do
  raise "oops"


  • Supported
    • MRI 1.9.2, 1.9.3
    • JRuby (1.9 mode) - advanced features unsupported
    • Rubinius (1.9 mode) - advanced features unsupported
  • Coming soon
    • MRI 2.0.0 - the official API for grabbing caller bindings is slated for MRI 2.0.0, but it has not been implemented yet

Get in touch!

If you’re using better_errors, I’d love to hear from you. Drop me a line and tell me what you think!


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Related Repositories



Better error page for Rack apps ...



API consumable error messages with ActiveModel::Errors drop-in compatibility. ...



Better error page for Rails and other Rack apps ...



Better error page for Rails and other Rack apps ...



Better error page for Rails and other Rack apps ...

Top Contributors

charliesome rstacruz rking shime quadule loopj jarrodrobins betawaffle brewski csexton ConradIrwin caldwell picandocodigo qqshfox jdelStrother simi josevalim lucascaton auxbuss mikian ndbroadbent i3zhe virusman zhouguangming


-   v0.6.0 zip tar
-   v0.5.0 zip tar
-   v0.3.2 zip tar
-   v0.3.0 zip tar
-   v0.2.0 zip tar
-   v0.1.1 zip tar
-   v0.1.0 zip tar
-   v0.0.8 zip tar
-   v0.0.7 zip tar
-   v0.0.6 zip tar
-   v0.0.5 zip tar
-   v0.0.4 zip tar
-   v0.0.3 zip tar
-   v0.0.2 zip tar
-   v0.0.1 zip tar