Include something more user friendly when we need to fail fatally and not just the technical error.tags/v1.11.90
@@ -107,9 +107,8 @@ CConn::CConn(const char* vncServerName, network::Socket* socket=NULL) | |||
} | |||
} catch (rdr::Exception& e) { | |||
vlog.error("%s", e.str()); | |||
if (alertOnFatalError) | |||
fl_alert("%s", e.str()); | |||
exit_vncviewer(); | |||
exit_vncviewer(_("Failed to connect to \"%s\":\n\n%s"), | |||
vncServerName, e.str()); | |||
return; | |||
} | |||
} | |||
@@ -264,13 +263,18 @@ void CConn::socketEvent(FL_SOCKET fd, void *data) | |||
cc->sock->outStream().flush(); | |||
} catch (rdr::EndOfStream& e) { | |||
vlog.info("%s", e.str()); | |||
exit_vncviewer(); | |||
if (!cc->desktop) { | |||
vlog.error(_("The connection was dropped by the server before " | |||
"the session could be established.")); | |||
exit_vncviewer(_("The connection was dropped by the server " | |||
"before the session could be established.")); | |||
} else { | |||
exit_vncviewer(); | |||
} | |||
} catch (rdr::Exception& e) { | |||
vlog.error("%s", e.str()); | |||
// Somebody might already have requested us to terminate, and | |||
// might have already provided an error message. | |||
if (!should_exit()) | |||
exit_vncviewer(e.str()); | |||
exit_vncviewer(_("An unexpected error occurred when communicating " | |||
"with the server:\n\n%s"), e.str()); | |||
} | |||
when = FL_READ | FL_EXCEPT; |
@@ -574,7 +574,8 @@ int Viewport::handle(int event) | |||
cc->sendClipboardData(filtered); | |||
} catch (rdr::Exception& e) { | |||
vlog.error("%s", e.str()); | |||
exit_vncviewer(e.str()); | |||
exit_vncviewer(_("An unexpected error occurred when communicating " | |||
"with the server:\n\n%s"), e.str()); | |||
} | |||
strFree(filtered); | |||
@@ -670,7 +671,8 @@ void Viewport::sendPointerEvent(const rfb::Point& pos, int buttonMask) | |||
cc->writer()->writePointerEvent(pos, buttonMask); | |||
} catch (rdr::Exception& e) { | |||
vlog.error("%s", e.str()); | |||
exit_vncviewer(e.str()); | |||
exit_vncviewer(_("An unexpected error occurred when communicating " | |||
"with the server:\n\n%s"), e.str()); | |||
} | |||
} else { | |||
if (!Fl::has_timeout(handlePointerTimeout, this)) | |||
@@ -769,7 +771,8 @@ void Viewport::handleClipboardChange(int source, void *data) | |||
self->cc->announceClipboard(true); | |||
} catch (rdr::Exception& e) { | |||
vlog.error("%s", e.str()); | |||
exit_vncviewer(e.str()); | |||
exit_vncviewer(_("An unexpected error occurred when communicating " | |||
"with the server:\n\n%s"), e.str()); | |||
} | |||
} | |||
@@ -781,7 +784,8 @@ void Viewport::flushPendingClipboard() | |||
cc->requestClipboard(); | |||
} catch (rdr::Exception& e) { | |||
vlog.error("%s", e.str()); | |||
exit_vncviewer(e.str()); | |||
exit_vncviewer(_("An unexpected error occurred when communicating " | |||
"with the server:\n\n%s"), e.str()); | |||
} | |||
} | |||
if (pendingClientClipboard) { | |||
@@ -789,7 +793,8 @@ void Viewport::flushPendingClipboard() | |||
cc->announceClipboard(true); | |||
} catch (rdr::Exception& e) { | |||
vlog.error("%s", e.str()); | |||
exit_vncviewer(e.str()); | |||
exit_vncviewer(_("An unexpected error occurred when communicating " | |||
"with the server:\n\n%s"), e.str()); | |||
} | |||
} | |||
@@ -815,7 +820,8 @@ void Viewport::handlePointerTimeout(void *data) | |||
self->lastButtonMask); | |||
} catch (rdr::Exception& e) { | |||
vlog.error("%s", e.str()); | |||
exit_vncviewer(e.str()); | |||
exit_vncviewer(_("An unexpected error occurred when communicating " | |||
"with the server:\n\n%s"), e.str()); | |||
} | |||
} | |||
@@ -884,7 +890,8 @@ void Viewport::handleKeyPress(int keyCode, rdr::U32 keySym) | |||
cc->writer()->writeKeyEvent(keySym, keyCode, true); | |||
} catch (rdr::Exception& e) { | |||
vlog.error("%s", e.str()); | |||
exit_vncviewer(e.str()); | |||
exit_vncviewer(_("An unexpected error occurred when communicating " | |||
"with the server:\n\n%s"), e.str()); | |||
} | |||
} | |||
@@ -918,7 +925,8 @@ void Viewport::handleKeyRelease(int keyCode) | |||
cc->writer()->writeKeyEvent(iter->second, keyCode, false); | |||
} catch (rdr::Exception& e) { | |||
vlog.error("%s", e.str()); | |||
exit_vncviewer(e.str()); | |||
exit_vncviewer(_("An unexpected error occurred when communicating " | |||
"with the server:\n\n%s"), e.str()); | |||
} | |||
downKeySym.erase(iter); |
@@ -107,12 +107,19 @@ static const char *about_text() | |||
return buffer; | |||
} | |||
void exit_vncviewer(const char *error) | |||
void exit_vncviewer(const char *error, ...) | |||
{ | |||
// Prioritise the first error we get as that is probably the most | |||
// relevant one. | |||
if ((error != NULL) && (exitError == NULL)) | |||
exitError = strdup(error); | |||
if ((error != NULL) && (exitError == NULL)) { | |||
va_list ap; | |||
va_start(ap, error); | |||
exitError = (char*)malloc(1024); | |||
if (exitError) | |||
(void) vsnprintf((char*)exitError, 1024, error, ap); | |||
va_end(ap); | |||
} | |||
exitMainloop = true; | |||
} | |||
@@ -416,7 +423,8 @@ potentiallyLoadConfigurationFile(char *vncServerName) | |||
} catch (rfb::Exception& e) { | |||
vlog.error("%s", e.str()); | |||
if (alertOnFatalError) | |||
fl_alert("%s", e.str()); | |||
fl_alert(_("Error reading configuration file \"%s\":\n\n%s"), | |||
vncServerName, e.str()); | |||
exit(EXIT_FAILURE); | |||
} | |||
} | |||
@@ -549,7 +557,7 @@ int main(int argc, char** argv) | |||
} catch (rfb::Exception& e) { | |||
vlog.error("%s", e.str()); | |||
if (alertOnFatalError) | |||
fl_alert("%s", e.str()); | |||
fl_alert(_("Error reading default configuration:\n\n%s"), e.str()); | |||
} | |||
for (int i = 1; i < argc;) { | |||
@@ -650,7 +658,7 @@ int main(int argc, char** argv) | |||
} catch (rdr::Exception& e) { | |||
vlog.error("%s", e.str()); | |||
if (alertOnFatalError) | |||
fl_alert("%s", e.str()); | |||
fl_alert(_("Failure waiting for incoming VNC connection:\n\n%s"), e.str()); | |||
exit_vncviewer(); | |||
return 1; | |||
} |
@@ -21,7 +21,13 @@ | |||
#define VNCSERVERNAMELEN 256 | |||
void exit_vncviewer(const char *error = NULL); | |||
#ifdef __GNUC__ | |||
# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) | |||
#else | |||
# define __printf_attr(a, b) | |||
#endif // __GNUC__ | |||
void exit_vncviewer(const char *error = NULL, ...) __printf_attr(1, 2); | |||
bool should_exit(); | |||
void about_vncviewer(); | |||
void run_mainloop(); |