Don't discard exception instance data in debug mode
If the debugger's monkey-patched raise was passed an instantiated exception, the #exception method was called with a potentially nil argument, causing its instance data to be thrown away. This hides potentially useful information from the user. Fix it by allowing instantiated exceptions to be reraised unharmed. Fixes Homebrew/homebrew#17622.
This commit is contained in:
parent
a79721e59d
commit
46e49c4889
@ -137,10 +137,18 @@ module RaisePlus
|
|||||||
|
|
||||||
def raise(*args)
|
def raise(*args)
|
||||||
exception = case
|
exception = case
|
||||||
when args.size == 0 then ($!.nil? ? RuntimeError.exception : $!)
|
when args.size == 0
|
||||||
when (args.size == 1 and args[0].is_a?(String)) then RuntimeError.exception(args[0])
|
$!.nil? ? RuntimeError.exception : $!
|
||||||
else args[0].exception(args[1]) # this does the right thing if args[1] is missing
|
when args.size == 1 && args[0].is_a?(String)
|
||||||
end
|
RuntimeError.exception(args[0])
|
||||||
|
when args.size == 2 && args[0].is_a?(Exception)
|
||||||
|
args[0].exception(args[1])
|
||||||
|
when args[0].is_a?(Class) && args[0].ancestors.include?(Exception)
|
||||||
|
args[0].exception(args[1])
|
||||||
|
else
|
||||||
|
args[0]
|
||||||
|
end
|
||||||
|
|
||||||
# passing something other than a String or Exception is illegal, but if someone does it anyway,
|
# passing something other than a String or Exception is illegal, but if someone does it anyway,
|
||||||
# that object won't have backtrace or continuation methods. in that case, let's pass it on to
|
# that object won't have backtrace or continuation methods. in that case, let's pass it on to
|
||||||
# the original raise, which will reject it
|
# the original raise, which will reject it
|
||||||
|
Loading…
x
Reference in New Issue
Block a user