Pretty Trace - Pretty Errors and Backtrace

Gem Travis Code Climate Gemnasium


Make your Ruby backtrace pretty again. Just require pretty_trace/enable in your ruby script, and errors will become clearer and more readable.


Install

$ gem install pretty_trace

Or with bundler:

$ gem 'pretty_trace', require: 'pretty_trace/enable'

Example

Create this ruby file:

# test.rb
require "pretty_trace/enable"
require "fileutils"
FileUtils.rm 'no_such_file'

Run it:

screenshot

Usage

The easiest way to use Pretty Trace is to require its activation script in your script:

require 'pretty_trace/enable'

From this point on, any exception will be formatted.

If you prefer to enable/disable the formatted backtrace manually, use PrettyTrace.enable and PrettyTrace.disable

require 'pretty_trace'

# Exceptions here will not be formatted

PrettyTrace.enable

# Exceptions here will be formatted

PrettyTrace.disable

# Exceptions here will not be formatted

Configuration

To filter out lines in the backtrace, use PrettyTrace.filter. This method accepts a single regular expression, or an array of regular expressions.

Note that you can call this method several times, and it will aggregate all your filters together.

require 'pretty_trace/enable'
PrettyTrace.filter /rails/
PrettyTrace.filter [/gem/, /lib/]

If you wish to temporarily disable Pretty Trace (for example, when you need to see the full trace paths), you can set the environment variable PRETTY_TRACE=off before running your script:

$ PRETTY_TRACE=off ruby myscript.rb