summaryrefslogtreecommitdiff
path: root/src/client.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2023-02-21 16:59:16 +1100
committerMaxime Coste <mawww@kakoune.org>2023-02-21 16:59:16 +1100
commitfa060c2a17e0b52dd5fb3fcd73aab3d176536fb8 (patch)
treecc3503fe6eb406cb3881c6e4d78afcb8605daeb1 /src/client.cc
parentbe49f362059c641ea58807cde3571b14be2cabe7 (diff)
Fix fatal exception when checking if buffer needs to be reloaded
If, for example, the buffer path now is a directory, MappedFile will throw on construction. Using a try block to explicitely allow errors fixes the issue.
Diffstat (limited to 'src/client.cc')
-rw-r--r--src/client.cc47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/client.cc b/src/client.cc
index cbdfa233..3ddddd87 100644
--- a/src/client.cc
+++ b/src/client.cc
@@ -367,31 +367,38 @@ void Client::check_if_buffer_needs_reloading()
if (not (buffer.flags() & Buffer::Flags::File) or reload == Autoreload::No)
return;
- const String& filename = buffer.name();
- const timespec ts = get_fs_timestamp(filename);
- const auto status = buffer.fs_status();
+ try
+ {
+ const String& filename = buffer.name();
+ const timespec ts = get_fs_timestamp(filename);
+ const auto status = buffer.fs_status();
- if (ts == InvalidTime or ts == status.timestamp)
- return;
+ if (ts == InvalidTime or ts == status.timestamp)
+ return;
- if (MappedFile fd{filename};
- fd.st.st_size == status.file_size and hash_data(fd.data, fd.st.st_size) == status.hash)
- return;
+ if (MappedFile fd{filename};
+ fd.st.st_size == status.file_size and hash_data(fd.data, fd.st.st_size) == status.hash)
+ return;
- if (reload == Autoreload::Ask)
+ if (reload == Autoreload::Ask)
+ {
+ StringView bufname = buffer.display_name();
+ info_show(format("reload '{}' ?", bufname),
+ format("'{}' was modified externally\n"
+ " y, <ret>: reload | n, <esc>: keep\n"
+ " Y: always reload | N: always keep\n",
+ bufname), {}, InfoStyle::Modal);
+
+ m_buffer_reload_dialog_opened = true;
+ m_input_handler.on_next_key("buffer-reload", KeymapMode::None, [this](Key key, Context&){ on_buffer_reload_key(key); });
+ }
+ else
+ reload_buffer();
+ }
+ catch (Kakoune::runtime_error& error)
{
- StringView bufname = buffer.display_name();
- info_show(format("reload '{}' ?", bufname),
- format("'{}' was modified externally\n"
- " y, <ret>: reload | n, <esc>: keep\n"
- " Y: always reload | N: always keep\n",
- bufname), {}, InfoStyle::Modal);
-
- m_buffer_reload_dialog_opened = true;
- m_input_handler.on_next_key("buffer-reload", KeymapMode::None, [this](Key key, Context&){ on_buffer_reload_key(key); });
+ write_to_debug_buffer(format("Error while checking if buffer {} changed: {}", buffer.name(), error.what()));
}
- else
- reload_buffer();
}
StringView Client::get_env_var(StringView name) const