all repos — listfix @ f5b5593c12f2ae9276fbe3db1150903dff4f0d62

Postfix Mailing List Software; Maintained on behalf the of Agency Economy Incorporated NFP.

Create class for exception handling.

Make a debug flag to print simple for complex messages.

	modified:   listfix.py
	modified:   listfix/__init__.py
	deleted:    listfix/error.py
	new file:   listfix/errors.py
Brian Barto bartobrian@gmail.com
Wed, 30 Mar 2022 15:22:26 -0400
commit

f5b5593c12f2ae9276fbe3db1150903dff4f0d62

parent

19a9648e98b8bae93fe8e7acd2a6696f3d7735b1

4 files changed, 21 insertions(+), 5 deletions(-)

jump to
M listfix.pylistfix.py

@@ -2,7 +2,7 @@ #!/usr/bin/python3

import sys import os -from listfix import Args, DB, Email, error_handler +from listfix import Args, DB, Email, Errors ######################## ## Function Defs

@@ -31,7 +31,8 @@ ########################

## Main Program ######################## -sys.excepthook = error_handler +er = Errors(debug=True) +er.set_exception_handler() ## Connect to DB (create DB if needed) and check tables.
M listfix/__init__.pylistfix/__init__.py

@@ -2,4 +2,4 @@

from .db import DB from .email import Email from .args import Args -from .error import error_handler +from .errors import Errors
D listfix/error.py

@@ -1,2 +0,0 @@

-def error_handler(exception_type, exception, traceback): - print(f"Error: {exception}")
A listfix/errors.py

@@ -0,0 +1,17 @@

+import sys + +class Errors: + + def __init__(self, debug=False): + self.debug = debug + self._exception_handler = None + + def set_exception_handler(self): + self._exception_handler = sys.excepthook + sys.excepthook = self.exception_handler + + def exception_handler(self, exception_type, exception, traceback): + if (self.debug): + self._exception_handler(exception_type, exception, traceback) + else: + print(f"Error: {exception}")