Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

call #to_s on exception_message before calling #split #622

Merged
merged 2 commits into from

3 participants

@slyphon

I figure I should mention this, even though i can't come up with an exact reproduction case (also, since it only seems to affect 1.8.7 it's probably just worth it to wait until EOL and say "sorry"), but...

When 1.8.7 is shutting down its threads, and you're stuck in a Monitor, it will eventually raise a SystemExit, and that SystemExit may have an instance of Exception as its #message (instead of a String) which causes the formatter to blow up.

I know this is the edgiest of edge cases (I seem to be on a streak this week of hitting all of these), but I hit this particular case, and thought "what the hell it's a one line patch"

@slyphon slyphon call #to_s on exception_message before calling #split
When 1.8.7 is shutting down its threads, and you're stuck in a Monitor,
it will eventually raise a SystemExit, and that SystemExit may have an
instance of Exception as its `#message` (instead of a String) which
causes the formatter to blow up.
2d39c46
@travisbot

This pull request passes (merged 2d39c46 into c9b8681).

@slyphon

this causes the exception on 1.8.7-p358 w/ rspec 3.8.0 (same code exists in master)

      it %[should report the correct error?] do
        th = Thread.new do
          raise RuntimeError, nil
        end

        lambda do
          begin
            th.join(5)
          rescue
            $stderr.puts $!.inspect
            raise
          end
        end.should raise_error(RuntimeError)
      end

winds up failing the test and shows this at the end:

  1) ZK::Pool Simple force_close! should report the correct error?
     Failure/Error: raise RuntimeError, nil
     SystemExit:
/Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/rspec-core-2.8.0/lib/rspec/core/formatters/base_text_formatter.rb:177:in `dump_failure_info': private method `split' called for #<RuntimeError: RuntimeError> (NoMethodError)
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/rspec-core-2.8.0/lib/rspec/core/formatters/base_text_formatter.rb:170:in `dump_failure'
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/rspec-core-2.8.0/lib/rspec/core/formatters/base_text_formatter.rb:19:in `dump_failures'
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/backports-2.5.3/lib/backports/1.8.7/enumerable.rb:67:in `each_with_index'
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/backports-2.5.3/lib/backports/1.8.7/enumerable.rb:67:in `each'
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/backports-2.5.3/lib/backports/1.8.7/enumerable.rb:67:in `each_with_index'
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/rspec-core-2.8.0/lib/rspec/core/formatters/base_text_formatter.rb:17:in `dump_failures'
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/rspec-core-2.8.0/lib/rspec/core/reporter.rb:98:in `send'
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/rspec-core-2.8.0/lib/rspec/core/reporter.rb:98:in `notify'
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/rspec-core-2.8.0/lib/rspec/core/reporter.rb:97:in `each'
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/rspec-core-2.8.0/lib/rspec/core/reporter.rb:97:in `notify'
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/rspec-core-2.8.0/lib/rspec/core/reporter.rb:81:in `finish'
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/rspec-core-2.8.0/lib/rspec/core/reporter.rb:36:in `report'
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:25:in `run'
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `autorun'
    from /Users/slyphon/.rvm/gems/ruby-1.8.7-p358@zk/bin/rspec:23
@dchelimsky
Owner

Be glad to merge this if you add an example that fails without this change.

@slyphon

@dchelimsky ok, that spec acts as proof

@dchelimsky dchelimsky merged commit 0d26b06 into rspec:master
@dchelimsky dchelimsky referenced this pull request from a commit
@dchelimsky dchelimsky Changelog for #622 [ci skip] 1482bfe
@dchelimsky dchelimsky referenced this pull request from a commit
@dchelimsky dchelimsky Changelog for #622 [ci skip] 53454f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 18, 2012
  1. @slyphon

    call #to_s on exception_message before calling #split

    slyphon authored
    When 1.8.7 is shutting down its threads, and you're stuck in a Monitor,
    it will eventually raise a SystemExit, and that SystemExit may have an
    instance of Exception as its `#message` (instead of a String) which
    causes the formatter to blow up.
  2. @slyphon
This page is out of date. Refresh to see the latest.
View
2  lib/rspec/core/formatters/base_text_formatter.rb
@@ -179,7 +179,7 @@ def dump_failure_info(example)
exception = example.execution_result[:exception]
output.puts "#{long_padding}#{red("Failure/Error:")} #{red(read_failed_line(exception, example).strip)}"
output.puts "#{long_padding}#{red(exception.class.name << ":")}" unless exception.class.name =~ /RSpec/
- exception.message.split("\n").each { |line| output.puts "#{long_padding} #{red(line)}" } if exception.message
+ exception.message.to_s.split("\n").each { |line| output.puts "#{long_padding} #{red(line)}" } if exception.message
if shared_group = find_shared_group(example)
dump_shared_failure_info(shared_group)
end
View
9 spec/rspec/core/formatters/base_text_formatter_spec.rb
@@ -65,6 +65,15 @@ def run_all_and_dump_failures
end
end
+ context "with an exception that has an exception instance as its message" do
+ it "should not raise NoMethodError" do
+ gonzo_exception = RuntimeError.new
+ gonzo_exception.stub(:message) { gonzo_exception }
+ group.example("example name") { raise gonzo_exception }
+ expect { run_all_and_dump_failures }.not_to raise_error(NoMethodError)
+ end
+ end
+
context "with an exception class other than RSpec" do
it "does not show the error class" do
group.example("example name") { raise NameError.new('foo') }
Something went wrong with that request. Please try again.