]> source.dussan.org Git - tigervnc.git/commitdiff
Deduplicate vncviewer error messages 1380/head
authorWilliam Sjöblom <wilsj@cendio.com>
Mon, 22 Nov 2021 16:36:35 +0000 (17:36 +0100)
committerWilliam Sjöblom <wilsj@cendio.com>
Tue, 23 Nov 2021 08:56:58 +0000 (09:56 +0100)
vncviewer previously had a the same localized error message duplicated
on a bunch of places. Pull these duplicates out into a single function.

vncviewer/CConn.cxx
vncviewer/Viewport.cxx
vncviewer/vncviewer.cxx
vncviewer/vncviewer.h

index ebdfbe87bba3e18aa862db4a355fbc474d46dd52..b1f97b9810b483306385ca71453fcc95cced4639 100644 (file)
@@ -277,8 +277,7 @@ void CConn::socketEvent(FL_SOCKET fd, void *data)
     }
   } catch (rdr::Exception& e) {
     vlog.error("%s", e.str());
-    abort_connection(_("An unexpected error occurred when communicating "
-                     "with the server:\n\n%s"), e.str());
+    abort_connection_with_unexpected_error(e);
   }
 
   when = FL_READ | FL_EXCEPT;
index 2f8a92c6112f2b09b93a6d868f586d12f4fb0a7d..34a943241921215d28913ce73923f5a93362bda8 100644 (file)
@@ -572,9 +572,7 @@ int Viewport::handle(int event)
       cc->sendClipboardData(filtered);
     } catch (rdr::Exception& e) {
       vlog.error("%s", e.str());
-      abort_connection(_("An unexpected error occurred when "
-                         "communicating with the server:\n\n%s"),
-                       e.str());
+      abort_connection_with_unexpected_error(e);
     }
 
     strFree(filtered);
@@ -670,9 +668,7 @@ void Viewport::sendPointerEvent(const rfb::Point& pos, int buttonMask)
       cc->writer()->writePointerEvent(pos, buttonMask);
     } catch (rdr::Exception& e) {
       vlog.error("%s", e.str());
-      abort_connection(_("An unexpected error occurred when "
-                         "communicating with the server:\n\n%s"),
-                       e.str());
+      abort_connection_with_unexpected_error(e);
     }
   } else {
     if (!Fl::has_timeout(handlePointerTimeout, this))
@@ -773,9 +769,7 @@ void Viewport::handleClipboardChange(int source, void *data)
     self->cc->announceClipboard(true);
   } catch (rdr::Exception& e) {
     vlog.error("%s", e.str());
-    abort_connection(_("An unexpected error occurred when "
-                       "communicating with the server:\n\n%s"),
-                     e.str());
+    abort_connection_with_unexpected_error(e);
   }
 }
 
@@ -788,9 +782,7 @@ void Viewport::flushPendingClipboard()
       cc->requestClipboard();
     } catch (rdr::Exception& e) {
       vlog.error("%s", e.str());
-      abort_connection(_("An unexpected error occurred when "
-                         "communicating with the server:\n\n%s"),
-                       e.str());
+      abort_connection_with_unexpected_error(e);
     }
   }
   if (pendingClientClipboard) {
@@ -799,9 +791,7 @@ void Viewport::flushPendingClipboard()
       cc->announceClipboard(true);
     } catch (rdr::Exception& e) {
       vlog.error("%s", e.str());
-      abort_connection(_("An unexpected error occurred when "
-                         "communicating with the server:\n\n%s"),
-                       e.str());
+      abort_connection_with_unexpected_error(e);
     }
   }
 
@@ -827,9 +817,7 @@ void Viewport::handlePointerTimeout(void *data)
                                           self->lastButtonMask);
   } catch (rdr::Exception& e) {
     vlog.error("%s", e.str());
-    abort_connection(_("An unexpected error occurred when "
-                       "communicating with the server:\n\n%s"),
-                     e.str());
+    abort_connection_with_unexpected_error(e);
   }
 }
 
@@ -898,9 +886,7 @@ void Viewport::handleKeyPress(int keyCode, rdr::U32 keySym)
       cc->writer()->writeKeyEvent(keySym, keyCode, true);
   } catch (rdr::Exception& e) {
     vlog.error("%s", e.str());
-    abort_connection(_("An unexpected error occurred when "
-                       "communicating with the server:\n\n%s"),
-                     e.str());
+    abort_connection_with_unexpected_error(e);
   }
 }
 
@@ -934,9 +920,7 @@ void Viewport::handleKeyRelease(int keyCode)
       cc->writer()->writeKeyEvent(iter->second, keyCode, false);
   } catch (rdr::Exception& e) {
     vlog.error("%s", e.str());
-    abort_connection(_("An unexpected error occurred when "
-                       "communicating with the server:\n\n%s"),
-                     e.str());
+    abort_connection_with_unexpected_error(e);
   }
 
   downKeySym.erase(iter);
index c8f5ef3b488a08d877a800cb79efba630bbd91a8..a083f0da3144e4ec71c4d4efe555f6eb081654ca 100644 (file)
@@ -56,6 +56,7 @@
 #include <rfb/LogWriter.h>
 #include <rfb/Timer.h>
 #include <rfb/Exception.h>
+#include <rdr/Exception.h>
 #include <network/TcpSocket.h>
 #include <os/os.h>
 
@@ -157,6 +158,11 @@ void abort_connection(const char *error, ...)
   exitMainloop = true;
 }
 
+void abort_connection_with_unexpected_error(const rdr::Exception &e) {
+  abort_connection(_("An unexpected error occurred when communicating "
+                     "with the server:\n\n%s"), e.str());
+}
+
 void disconnect()
 {
   exitMainloop = true;
index 57eb91fb35244c36465cd8ce569d319bc9f2d88c..199e2e2c52a9664223df75a2b92af3067b10c7a4 100644 (file)
 #  define __printf_attr(a, b)
 #endif // __GNUC__
 
+namespace rdr {
+  struct Exception;
+};
+
 void abort_vncviewer(const char *error, ...) __printf_attr(1, 2);
 void abort_connection(const char *error, ...) __printf_attr(1, 2);
+void abort_connection_with_unexpected_error(const rdr::Exception &);
+
 void disconnect();
 bool should_disconnect();