Skip to content

Commit

Permalink
Improve Listen warning when block raise an execption (add backtrace)
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudgg committed Sep 4, 2013
1 parent f20007b commit 5ed90c7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/listen/listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ def on_change(directories, options = {})
block.call(changes[:modified], changes[:added], changes[:removed])
end
rescue => ex
Kernel.warn "[Listen warning]: Change block raise an execption: #{ex.inspect}"
Kernel.warn "[Listen warning]: Change block raise an execption: #{$!}"
Kernel.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
end

private
Expand Down
4 changes: 3 additions & 1 deletion spec/listen/listener_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Listen::Adapter.stub(:select_and_initialize) { adapter }
# Don't build a record of the files inside the base directory.
Listen::DirectoryRecord.any_instance.stub(:build)
Kernel.stub(:warn)
end
subject { described_class.new(watched_directories) }

Expand Down Expand Up @@ -209,7 +210,8 @@
end

it "stops the adapter and warns" do
Kernel.should_receive(:warn).with("[Listen warning]: Change block raise an execption: #<RuntimeError: foo>")
Kernel.should_receive(:warn).with("[Listen warning]: Change block raise an execption: foo")
Kernel.should_receive(:warn).with(/^Backtrace:.*/)
subject.on_change(directories)
end

Expand Down

0 comments on commit 5ed90c7

Please sign in to comment.