1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-29 10:02:57 +03:00

Gracefully handle exception when opening files given on command line

Fixes #310
This commit is contained in:
Maxime Coste 2015-07-08 13:43:40 +01:00
parent f65d41a30a
commit 123541822b
2 changed files with 23 additions and 11 deletions

View File

@ -11,7 +11,10 @@
namespace Kakoune namespace Kakoune
{ {
struct name_not_unique : logic_error {}; struct name_not_unique : runtime_error
{
name_not_unique() : runtime_error("buffer name is already in use") {}
};
BufferManager::~BufferManager() BufferManager::~BufferManager()
{ {

View File

@ -228,7 +228,7 @@ void register_options()
} }
template<typename UI> template<typename UI>
void create_local_client(StringView init_command, bool kakrc_error) void create_local_client(StringView init_command, bool startup_error)
{ {
struct LocalUI : UI struct LocalUI : UI
{ {
@ -262,9 +262,9 @@ void create_local_client(StringView init_command, bool kakrc_error)
static Client* client = ClientManager::instance().create_client( static Client* client = ClientManager::instance().create_client(
make_unique<LocalUI>(), get_env_vars(), init_command); make_unique<LocalUI>(), get_env_vars(), init_command);
if (kakrc_error) if (startup_error)
client->print_status({ client->print_status({
"error while sourcing kakrc, see *debug* buffer for details", "error during startup, see *debug* buffer for details",
get_face("Error") get_face("Error")
}); });
@ -395,7 +395,7 @@ int run_server(StringView session, StringView init_command,
Server server(session.empty() ? to_string(getpid()) : session.str()); Server server(session.empty() ? to_string(getpid()) : session.str());
bool kakrc_error = false; bool startup_error = false;
if (not ignore_kakrc) try if (not ignore_kakrc) try
{ {
Context initialisation_context{Context::EmptyContextFlag{}}; Context initialisation_context{Context::EmptyContextFlag{}};
@ -404,12 +404,12 @@ int run_server(StringView session, StringView init_command,
} }
catch (Kakoune::runtime_error& error) catch (Kakoune::runtime_error& error)
{ {
kakrc_error = true; startup_error = true;
write_to_debug_buffer(format("error while parsing kakrc:\n {}", error.what())); write_to_debug_buffer(format("error while parsing kakrc:\n {}", error.what()));
} }
catch (Kakoune::client_removed&) catch (Kakoune::client_removed&)
{ {
kakrc_error = true; startup_error = true;
write_to_debug_buffer("error while parsing kakrc: asked to quit"); write_to_debug_buffer("error while parsing kakrc: asked to quit");
} }
@ -423,10 +423,19 @@ int run_server(StringView session, StringView init_command,
// create buffers in reverse order so that the first given buffer // create buffers in reverse order so that the first given buffer
// is the most recently created one. // is the most recently created one.
for (auto& file : reversed(files)) for (auto& file : reversed(files))
{
try
{ {
if (not create_buffer_from_file(file)) if (not create_buffer_from_file(file))
new Buffer(file.str(), Buffer::Flags::New | Buffer::Flags::File); new Buffer(file.str(), Buffer::Flags::New | Buffer::Flags::File);
} }
catch (Kakoune::runtime_error& error)
{
startup_error = true;
write_to_debug_buffer(format("error while opening file '{}':\n {}",
file, error.what()));
}
}
} }
catch (Kakoune::runtime_error& error) catch (Kakoune::runtime_error& error)
{ {
@ -438,9 +447,9 @@ int run_server(StringView session, StringView init_command,
if (not daemon) if (not daemon)
{ {
if (dummy_ui) if (dummy_ui)
create_local_client<DummyUI>(init_command, kakrc_error); create_local_client<DummyUI>(init_command, startup_error);
else else
create_local_client<NCursesUI>(init_command, kakrc_error); create_local_client<NCursesUI>(init_command, startup_error);
} }
while (not terminate and (not client_manager.empty() or daemon)) while (not terminate and (not client_manager.empty() or daemon))