Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Enter the context of exceptions
Ruby Perl Shell

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
test
.gemtest
.gitignore
.travis.yml
.yardopts
CHANGELOG
Gemfile
LICENSE
README.md
Rakefile
pry-exception_explorer.gemspec

README.md

pry-exception_explorer

(C) John Mair (banisterfiend) 2011

Enter the context of exceptions

Please note, this is a first release for pry-exception_explorer and as such it may still have teething problems. If you encounter any quirks or crashes please file an issue

pry-exception_explorer is an interactive error console for Ruby 1.9.2+ inspired by the Hammertime gem, which was in turn inspired by consoles found in the Lisp and Smalltalk environments. pry-exception_explorer is a plugin for the Pry REPL.

Using pry-exception_explorer we can automatically pull up a Pry session at the point an exception arises and use Pry to inspect the state there to debug (and fix) the problem. We also get access to the entire call stack of the exception and can walk the stack to interactively examine the state in parent frames (using pry-stack_explorer).

Watch the mini-screencast: http://vimeo.com/36061298

Example:

In the Ruby file:

require 'pry-exception_explorer'

PryExceptionExplorer.enabled = true
PryExceptionExplorer.intercept(ArgumentError)

def alpha
  name = "john"
  beta
  puts name
end

def beta
  x = "john"
  gamma(x)
end

def gamma(x)
  raise ArgumentError, "x must be a number!" if !x.is_a?(Numeric)
  puts "2 * x = #{2 * x}"
end

alpha

The following session starts up:

Frame number: 0/4
Frame type: method

From: /Users/john/ruby/projects/pry-exception_explorer/examples/example_inline.rb @ line 23 in Object#gamma:

    18:   x = "john"
    19:   gamma(x)
    20: end
    21:
    22: def gamma(x)
 => 23:   raise ArgumentError, "x must be a number!" if !x.is_a?(Numeric)
    24:   puts "2 * x = #{2 * x}"
    25: end
    26:
    27: alpha

[1] (pry) main: 0> x
=> "john"
[2] (pry) main: 0> x = 7
=> 7
[3] (pry) main: 0> continue-exception

Since we fixed the problem (invalid type for x local) we can continue-exception, and have the method continue with the amended x:

PROGRAM OUTPUT:

2 * x = 14

john

Features and limitations

Features

  • Puts you in context of exception.
  • Makes entire call stack accessible (useful for drilling down to precise cause of error).
  • Allows you to 'continue' from exception, recovering from error (continue-exception command)
  • Has limited/experimental ability to intercept exceptions that arise from C code (use pry --c-exceptions to enable).
  • Let's you assert over state of entire stack when determining whether an exception should be intercepted.
  • Let's you start the session on any stack frame.

Limitations

  • Only works on Ruby 1.9.2+ (including 1.9.3) MRI.
  • Limited support for C exceptions -- only some exceptions that arise from C code are caught.
  • Wiki documentation coming soon ;)

Contact

Problems or questions contact me at github

License

(The MIT License)

Copyright (c) 2011 John Mair (banisterfiend)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.