[Git][NTPsec/ntpsec][master] Improve error handling.

Eric S. Raymond gitlab at mg.gitlab.com
Sat Dec 10 17:59:14 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
573ca5f7 by Eric S. Raymond at 2016-12-10T12:55:41-05:00
Improve error handling.

- - - - -


3 changed files:

- ntpclients/ntpdig
- ntpclients/ntpmon
- pylib/packet.py


Changes:

=====================================
ntpclients/ntpdig
=====================================
--- a/ntpclients/ntpdig
+++ b/ntpclients/ntpdig
@@ -360,7 +360,7 @@ if __name__ == '__main__':
             try:
                 returned += queryhost(server=server, concurrent=True, timeout=timeout)
             except ntp.packet.SyncException as e:
-                log(e.message)
+                log(str(e))
                 continue
             if len(returned) >= samples:
                 break
@@ -368,7 +368,7 @@ if __name__ == '__main__':
             try:
                 returned += queryhost(server=server, concurrent=False, timeout=timeout)
             except ntp.packet.SyncException as e:
-                log(e.message)
+                log(str(e))
                 continue
             if len(returned) >= samples:
                 break


=====================================
ntpclients/ntpmon
=====================================
--- a/ntpclients/ntpmon
+++ b/ntpclients/ntpmon
@@ -156,7 +156,7 @@ if __name__ == '__main__':
                 time.sleep(min(hpolls) / 2)
     except KeyboardInterrupt:
         print("")
-    except Fatal as e:
+    except (Fatal, ntp.packet.ControlException) as e:
         print(e)
     except IOError:
         print("Bailing out...")


=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -352,6 +352,8 @@ class SyncException(BaseException):
     def __init__(self, message, errorcode=0):
         self.message = message
         self.errorcode = errorcode
+    def __str__(self):
+        return self.message
 
 class SyncPacket(Packet):
     "Mode 1-5 time-synchronization packet, including SNTP."
@@ -688,6 +690,8 @@ class ControlException(BaseException):
     def __init__(self, message, errorcode=0):
         self.message = message
         self.errorcode = errorcode
+    def __str__(self):
+        return self.message
 
 class ControlSession:
     "A session to a host"



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/573ca5f7e4b68851e9b17b3e54a0bfabb7018284
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161210/213076f0/attachment.html>


More information about the vc mailing list