Skip to content

Commit

Permalink
issue guard#487: use Listen.logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinDKelley committed Oct 29, 2020
1 parent d2ac55a commit 0e9663c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 19 deletions.
14 changes: 0 additions & 14 deletions lib/listen/event/loop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,6 @@ def _process_changes
transition! :started

processor.loop_for(@config.min_delay_between_events)

rescue StandardError => ex
_nice_error(ex)
end

def _nice_error(ex)
indent = "\n -- "
msg = format(
'exception while processing events: %s Backtrace:%s%s',
ex,
indent,
ex.backtrace * indent
)
Listen::Logger.error(msg)
end

def _wakeup(reason)
Expand Down
2 changes: 1 addition & 1 deletion lib/listen/thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def new(name)
def _log_exception(ex, thread_name, caller_stack)
complete_backtrace = [*ex.backtrace, "--- Thread.new ---", *caller_stack]
message = "Exception rescued in #{thread_name}:\n#{_exception_with_causes(ex)}\n#{complete_backtrace * "\n"}"
Listen::Logger.error(message)
Listen.logger.error(message)
end

def _exception_with_causes(ex)
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/listen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
around { |example| fixtures { example.run } }

context 'with change block raising' do
let(:callback) { ->(_, _, _) { fail 'foo' } }
let(:callback) { ->(_, _, _) { raise 'foo' } }
let(:wrapper) { setup_listener(all_options, callback) }

it 'warns the backtrace' do
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/listen/thread_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
end

it "rescues and logs exceptions" do
expect(Listen::Logger).to receive(:error)
expect(Listen.logger).to receive(:error)
.with(/Exception rescued in listen-worker_thread:\nArgumentError: boom!\n.*\/listen\/thread_spec\.rb/)
subject.join
end

it "rescues and logs backtrace + exception backtrace" do
expect(Listen::Logger).to receive(:error)
expect(Listen.logger).to receive(:error)
.with(/Exception rescued in listen-worker_thread:\nArgumentError: boom!\n.*\/listen\/thread\.rb.*--- Thread.new ---.*\/listen\/thread_spec\.rb/m)
subject.join
end
Expand All @@ -48,7 +48,7 @@
end

it "details exception causes" do
expect(Listen::Logger).to receive(:error)
expect(Listen.logger).to receive(:error)
.with(/RuntimeError: nested outer\n--- Caused by: ---\nRuntimeError: nested inner\n--- Caused by: ---\nArgumentError: boom!/)
subject.join
end
Expand Down

0 comments on commit 0e9663c

Please sign in to comment.