ruby/ruby — pull request #434 by makimoto (2013-10-30 10:29:58+00:00)
Title: Prevent irb from crashing when exception with nil backtrace is raised

This pull req fixes irb's unexpected crash.

When an exception whose backtrace is `nil` is raised, irb crashes and exits.
irb requires `#backtrace` with `Exception` but some exceptions have not their backtraces.
An example of such exceptions I found is `ActionView::Template::Error`.
With such exception, irb crashes with `NoMethodError` as the following:

```
> irb
irb(main):001:0> require 'action_view'
=> true
irb(main):002:0> e = ActionView::Template::Error.new(:foo, Exception.new)
=> #
irb(main):003:0> raise e
ActionView::Template::Error: Exception
/Users/makimoto/.rbenv/versions/trunk/lib/ruby/2.1.0/irb.rb:502:in `block (2 levels) in eval_input': undefined method `[]' for nil:NilClass (NoMethodError)
from /Users/makimoto/.rbenv/versions/trunk/lib/ruby/2.1.0/irb.rb:624:in `signal_status'
from /Users/makimoto/.rbenv/versions/trunk/lib/ruby/2.1.0/irb.rb:489:in `block in eval_input'
from /Users/makimoto/.rbenv/versions/trunk/lib/ruby/2.1.0/irb/ruby-lex.rb:247:in `block (2 levels) in each_top_level_statement'
from /Users/makimoto/.rbenv/versions/trunk/lib/ruby/2.1.0/irb/ruby-lex.rb:233:in `loop'
from /Users/makimoto/.rbenv/versions/trunk/lib/ruby/2.1.0/irb/ruby-lex.rb:233:in `block in each_top_level_statement'
from /Users/makimoto/.rbenv/versions/trunk/lib/ruby/2.1.0/irb/ruby-lex.rb:232:in `catch'
from /Users/makimoto/.rbenv/versions/trunk/lib/ruby/2.1.0/irb/ruby-lex.rb:232:in `each_top_level_statement'
from /Users/makimoto/.rbenv/versions/trunk/lib/ruby/2.1.0/irb.rb:488:in `eval_input'
from /Users/makimoto/.rbenv/versions/trunk/lib/ruby/2.1.0/irb.rb:397:in `block in start'
from /Users/makimoto/.rbenv/versions/trunk/lib/ruby/2.1.0/irb.rb:396:in `catch'
from /Users/makimoto/.rbenv/versions/trunk/lib/ruby/2.1.0/irb.rb:396:in `start'
from /Users/makimoto/.rbenv/versions/trunk/bin/irb:11:in `

'
>
```

With my patch, `irb` just shows ordinary exception messages without crash.

```
> irb
irb(main):001:0> require 'action_view'
=> true
irb(main):002:0> e = ActionView::Template::Error.new(:foo, Exception.new)
=> #
irb(main):003:0> raise e
ActionView::Template::Error: Exception

irb(main):004:0>
```

(Of course, such exceptions are bad-mannered. However, they can occur actually. So it should be fixed.)