Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #509: raise Listen::Error::INotifyMaxWatchesExceeded rather than abort #545

Merged
merged 2 commits into from Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/listen/adapter/linux.rb
Expand Up @@ -24,17 +24,14 @@ 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
Unable to monitor directories for changes because iNotify max watches exceeded. See #{README_URL} .
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