Skip to content

Commit

Permalink
issue guard#509: raise Listen::Error::INotifyMaxWatchesExceeded rathe…
Browse files Browse the repository at this point in the history
…r than abort
  • Loading branch information
ColinDKelley committed Aug 15, 2021
1 parent 306a8bc commit a678b9e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
10 changes: 4 additions & 6 deletions lib/listen/adapter/linux.rb
Expand Up @@ -24,17 +24,15 @@ class Linux < Base
README_URL = 'https://github.com/guard/listen'\
'/blob/master/README.md#increasing-the-amount-of-inotify-watchers'

INOTIFY_LIMIT_MESSAGE = <<-EOS
FATAL: Listen error: unable to monitor directories for changes.
Visit #{README_URL} for info on how to fix this.
EOS

def _configure(directory, &callback)
require 'rb-inotify'
@worker ||= ::INotify::Notifier.new
@worker.watch(directory.to_s, *options.events, &callback)
rescue Errno::ENOSPC
abort(INOTIFY_LIMIT_MESSAGE)
raise ::Listen::Error::INotifyMaxWatchesExceeded, <<~EOS
FATAL: Listen error: Unable to monitor directories for changes because iNotify max watches exceeded.
Visit #{README_URL} for info on how to fix this.
EOS
end

def _run
Expand Down
1 change: 1 addition & 0 deletions lib/listen/error.rb
Expand Up @@ -6,5 +6,6 @@ module Listen
class Error < RuntimeError
class NotStarted < Error; end
class SymlinkLoop < Error; end
class INotifyMaxWatchesExceeded < Error; end
end
end
7 changes: 3 additions & 4 deletions spec/lib/listen/adapter/linux_spec.rb
Expand Up @@ -58,7 +58,7 @@
end
end

describe 'inotify limit message' do
describe 'inotify max watches exceeded' do
let(:directories) { [Pathname.pwd] }
let(:adapter_options) { {} }

Expand All @@ -74,9 +74,8 @@
allow(config).to receive(:adapter_options).and_return(adapter_options)
end

it 'should be shown before calling abort' do
expected_message = described_class.const_get('INOTIFY_LIMIT_MESSAGE')
expect { subject.start }.to raise_error SystemExit, expected_message
it 'raises exception' do
expect { subject.start }.to raise_exception(Listen::Error::INotifyMaxWatchesExceeded, /inotify max watches exceeded/i)
end
end

Expand Down

0 comments on commit a678b9e

Please sign in to comment.