Extract xmessage/MessageBox support in a notify_fatal_error function

This commit is contained in:
Maxime Coste 2015-05-29 13:35:09 +01:00
parent 336df38237
commit 3c86484c4e
3 changed files with 29 additions and 17 deletions

View File

@ -25,6 +25,26 @@ private:
String m_message;
};
bool notify_fatal_error(const String& msg)
{
#if defined(__CYGWIN__)
int res = MessageBox(NULL, msg.c_str(), "Kakoune: assert failed",
MB_OKCANCEL | MB_ICONERROR);
switch (res)
{
case IDCANCEL:
return false;
case IDOK:
return true;
}
#elif defined(__linux__)
auto cmd = "xmessage -buttons 'quit:0,ignore:1' '" + msg + "'";
if (system(cmd.c_str()) == 1)
return true;
#endif
return false;
}
void on_assert_failed(const char* message)
{
char* callstack = Backtrace{}.desc();
@ -33,23 +53,8 @@ void on_assert_failed(const char* message)
write_debug(format("assert failed: '{}'\n{}", message, debug_info));
const auto msg = format("{}\n[Debug Infos]\n{}", message, debug_info);
#if defined(__CYGWIN__)
int res = MessageBox(NULL, msg.c_str(), "Kakoune: assert failed",
MB_OKCANCEL | MB_ICONERROR);
switch (res)
{
case IDCANCEL:
throw assert_failed(message);
case IDOK:
return;
}
#elif defined(__linux__)
auto cmd = "xmessage -buttons 'quit:0,ignore:1' '" + msg + "'";
if (system(cmd.c_str()) != 1)
if (not notify_fatal_error(msg))
throw assert_failed(msg);
#else
throw assert_failed(msg);
#endif
}
}

View File

@ -4,6 +4,11 @@
namespace Kakoune
{
class String;
// return true if user asked to ignore the error
bool notify_fatal_error(const String& message);
void on_assert_failed(const char* message);
}

View File

@ -284,8 +284,10 @@ void signal_handler(int signal)
if (signal != SIGTERM)
{
char* callstack = Backtrace{}.desc();
write_stderr(format("Received {}, exiting.\nCallstack:\n{}", text, callstack));
auto msg = format("Received {}, exiting.\nCallstack:\n{}", text, callstack);
free(callstack);
write_stderr(msg);
notify_fatal_error(msg);
}
if (Server::has_instance())