From 12c327332e7b059edbc83ce476f41870fb2a2432 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 | 5 +++-- lib/listen/error.rb | 1 + spec/lib/listen/adapter/linux_spec.rb | 7 +++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/listen/adapter/linux.rb b/lib/listen/adapter/linux.rb index af732491..063d65cc 100644 --- a/lib/listen/adapter/linux.rb +++ b/lib/listen/adapter/linux.rb @@ -24,8 +24,9 @@ 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. + INOTIFY_LIMIT_MESSAGE = <<~EOS + FATAL: Listen error: iNotify max watches exceeded. + Unable to monitor directories for changes. Visit #{README_URL} for info on how to fix this. EOS 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 9d9caff6..19f51857 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