From 33546346058f4e521d35fab53b8a4b626ef6e494 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Mon, 12 Dec 2022 09:12:30 -0800 Subject: [PATCH] Improve error handling upon watch directory setup (#4355) Failing to handle the exception may lead to a critical log message (minor) and a crash during startup (major). --- gtk/Session.cc | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/gtk/Session.cc b/gtk/Session.cc index d2b47e35e..f89c53036 100644 --- a/gtk/Session.cc +++ b/gtk/Session.cc @@ -740,15 +740,27 @@ void Session::Impl::watchdir_update() monitor_.reset(); } - if (is_enabled && monitor_ == nullptr) + if (!is_enabled || monitor_ != nullptr) { - auto const m = dir->monitor_directory(); - watchdir_scan(); - - monitor_ = m; - monitor_dir_ = dir; - monitor_tag_ = m->signal_changed().connect(sigc::mem_fun(*this, &Impl::on_file_changed_in_watchdir)); + return; } + + auto monitor = Glib::RefPtr(); + + try + { + monitor = dir->monitor_directory(); + } + catch (Glib::Error const&) + { + return; + } + + watchdir_scan(); + + monitor_ = monitor; + monitor_dir_ = dir; + monitor_tag_ = monitor_->signal_changed().connect(sigc::mem_fun(*this, &Impl::on_file_changed_in_watchdir)); } /***