From 0cb9a497050169c6de67da33291c606e5289685a Mon Sep 17 00:00:00 2001 From: John Mair Date: Sun, 20 Jan 2013 03:50:38 +0100 Subject: [PATCH] add Pry.last_internal_error This is set to the last CommandError, SlopError, etc. Most often raised by commands. This info is useful to pry devs debugging otherwise opaque command errors. --- lib/pry/pry_class.rb | 4 ++++ lib/pry/pry_instance.rb | 1 + 2 files changed, 5 insertions(+) diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index 3694b496..a779c404 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -55,6 +55,10 @@ class Pry # @return [Binding] A top level binding with no local variables attr_accessor :toplevel_binding + # @return [Exception, nil] The last pry internal error. + # (a CommandError in most cases) + attr_accessor :last_internal_error + # plugin forwardables def_delegators :@plugin_manager, :plugins, :load_plugins, :locate_plugins diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 292d932d..58bee49f 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -446,6 +446,7 @@ class Pry def process_command_safely(val) process_command(val) rescue CommandError, Slop::InvalidOptionError, MethodSource::SourceNotFoundError => e + Pry.last_internal_error = e output.puts "Error: #{e.message}" true end