From: Pierre Ossman Date: Thu, 21 May 2020 11:41:03 +0000 (+0200) Subject: Better error messages when terminating X-Git-Tag: v1.11.90~74^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8ddebf6dd2dca7be98230e2b8d567c70833bd5a7;p=tigervnc.git Better error messages when terminating Include something more user friendly when we need to fail fatally and not just the technical error. --- diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx index 68dd031b..e73f5db9 100644 --- a/vncviewer/CConn.cxx +++ b/vncviewer/CConn.cxx @@ -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; diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx index b0b2a15a..c1c58622 100644 --- a/vncviewer/Viewport.cxx +++ b/vncviewer/Viewport.cxx @@ -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); diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index 39a267c0..a93a3b08 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -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; } diff --git a/vncviewer/vncviewer.h b/vncviewer/vncviewer.h index 88aa9332..494611b7 100644 --- a/vncviewer/vncviewer.h +++ b/vncviewer/vncviewer.h @@ -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();