mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Move raise-up impl out of the middle of the REPL methods
This commit is contained in:
parent
10b223855e
commit
b7112667ef
1 changed files with 42 additions and 43 deletions
|
@ -266,48 +266,6 @@ class Pry
|
||||||
exec_hook :after_eval, result, self
|
exec_hook :after_eval, result, self
|
||||||
end
|
end
|
||||||
|
|
||||||
# Raise an exception out of Pry.
|
|
||||||
#
|
|
||||||
# See Kernel#raise for documentation of parameters.
|
|
||||||
# See rb_make_exception for the inbuilt implementation.
|
|
||||||
#
|
|
||||||
# This is necessary so that the raise-up command can tell the
|
|
||||||
# difference between an exception the user has decided to raise,
|
|
||||||
# and a mistake in specifying that exception.
|
|
||||||
#
|
|
||||||
# (i.e. raise-up RunThymeError.new should not be the same as
|
|
||||||
# raise-up NameError, "unititialized constant RunThymeError")
|
|
||||||
|
|
||||||
def raise_up_common(force, *args)
|
|
||||||
exception = if args == []
|
|
||||||
last_exception || RuntimeError.new
|
|
||||||
elsif args.length == 1 && args.first.is_a?(String)
|
|
||||||
RuntimeError.new(args.first)
|
|
||||||
elsif args.length > 3
|
|
||||||
raise ArgumentError, "wrong number of arguments"
|
|
||||||
elsif !args.first.respond_to?(:exception)
|
|
||||||
raise TypeError, "exception class/object expected"
|
|
||||||
elsif args.length === 1
|
|
||||||
args.first.exception
|
|
||||||
else
|
|
||||||
args.first.exception(args[1])
|
|
||||||
end
|
|
||||||
|
|
||||||
raise TypeError, "exception object expected" unless exception.is_a? Exception
|
|
||||||
|
|
||||||
exception.set_backtrace(args.length === 3 ? args[2] : caller(1))
|
|
||||||
|
|
||||||
if force || binding_stack.one?
|
|
||||||
binding_stack.clear
|
|
||||||
throw :raise_up, exception
|
|
||||||
else
|
|
||||||
binding_stack.pop
|
|
||||||
raise exception
|
|
||||||
end
|
|
||||||
end
|
|
||||||
def raise_up(*args); raise_up_common(false, *args); end
|
|
||||||
def raise_up!(*args); raise_up_common(true, *args); end
|
|
||||||
|
|
||||||
# Perform a read.
|
# Perform a read.
|
||||||
# If no parameter is given, default to top-level (main).
|
# If no parameter is given, default to top-level (main).
|
||||||
# This is a multi-line read; so the read continues until a valid
|
# This is a multi-line read; so the read continues until a valid
|
||||||
|
@ -566,7 +524,6 @@ class Pry
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private :handle_read_errors
|
private :handle_read_errors
|
||||||
|
|
||||||
# Returns the next line of input to be used by the pry instance.
|
# Returns the next line of input to be used by the pry instance.
|
||||||
|
@ -694,4 +651,46 @@ class Pry
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raise an exception out of Pry.
|
||||||
|
#
|
||||||
|
# See Kernel#raise for documentation of parameters.
|
||||||
|
# See rb_make_exception for the inbuilt implementation.
|
||||||
|
#
|
||||||
|
# This is necessary so that the raise-up command can tell the
|
||||||
|
# difference between an exception the user has decided to raise,
|
||||||
|
# and a mistake in specifying that exception.
|
||||||
|
#
|
||||||
|
# (i.e. raise-up RunThymeError.new should not be the same as
|
||||||
|
# raise-up NameError, "unititialized constant RunThymeError")
|
||||||
|
#
|
||||||
|
def raise_up_common(force, *args)
|
||||||
|
exception = if args == []
|
||||||
|
last_exception || RuntimeError.new
|
||||||
|
elsif args.length == 1 && args.first.is_a?(String)
|
||||||
|
RuntimeError.new(args.first)
|
||||||
|
elsif args.length > 3
|
||||||
|
raise ArgumentError, "wrong number of arguments"
|
||||||
|
elsif !args.first.respond_to?(:exception)
|
||||||
|
raise TypeError, "exception class/object expected"
|
||||||
|
elsif args.length === 1
|
||||||
|
args.first.exception
|
||||||
|
else
|
||||||
|
args.first.exception(args[1])
|
||||||
|
end
|
||||||
|
|
||||||
|
raise TypeError, "exception object expected" unless exception.is_a? Exception
|
||||||
|
|
||||||
|
exception.set_backtrace(args.length === 3 ? args[2] : caller(1))
|
||||||
|
|
||||||
|
if force || binding_stack.one?
|
||||||
|
binding_stack.clear
|
||||||
|
throw :raise_up, exception
|
||||||
|
else
|
||||||
|
binding_stack.pop
|
||||||
|
raise exception
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def raise_up(*args); raise_up_common(false, *args); end
|
||||||
|
def raise_up!(*args); raise_up_common(true, *args); end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue