From a678b9eeeb07fd3c977f983b8ff2104075110319 Mon Sep 17 00:00:00 2001 From: Colin Kelley Date: Sat, 14 Aug 2021 22:57:15 -0700 Subject: [PATCH] issue #509: raise Listen::Error::INotifyMaxWatchesExceeded rather than abort --- lib/listen/adapter/linux.rb | 10 ++++------ lib/listen/error.rb | 1 + spec/lib/listen/adapter/linux_spec.rb | 7 +++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/listen/adapter/linux.rb b/lib/listen/adapter/linux.rb index af732491..26d1ddff 100644 --- a/lib/listen/adapter/linux.rb +++ b/lib/listen/adapter/linux.rb @@ -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 diff --git a/lib/listen/error.rb b/lib/listen/error.rb index e3c3a27c..a5f2dc11 100644 --- a/lib/listen/error.rb +++ b/lib/listen/error.rb @@ -6,5 +6,6 @@ module Listen class Error < RuntimeError class NotStarted < Error; end class SymlinkLoop < Error; end + class INotifyMaxWatchesExceeded < Error; end end end diff --git a/spec/lib/listen/adapter/linux_spec.rb b/spec/lib/listen/adapter/linux_spec.rb index 2c8fc8f2..e55bbf67 100644 --- a/spec/lib/listen/adapter/linux_spec.rb +++ b/spec/lib/listen/adapter/linux_spec.rb @@ -58,7 +58,7 @@ end end - describe 'inotify limit message' do + describe 'inotify max watches exceeded' do let(:directories) { [Pathname.pwd] } let(:adapter_options) { {} } @@ -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