added a dictionary checker and added log display to log_exception
This commit is contained in:
parent
a605b6675e
commit
104e665d8a
|
|
@ -5,6 +5,7 @@ import traceback
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Define the error codes
|
# Define the error codes
|
||||||
|
import rich
|
||||||
|
|
||||||
_ERRORS = ["ParsingError"]
|
_ERRORS = ["ParsingError"]
|
||||||
__all__ = _ERRORS+[]
|
__all__ = _ERRORS+[]
|
||||||
|
|
@ -60,6 +61,7 @@ def log_exception(exception, level="ERROR"):
|
||||||
"""
|
"""
|
||||||
level = level.lower()
|
level = level.lower()
|
||||||
logging.__getattribute__(level)(traceback.format_exc())
|
logging.__getattribute__(level)(traceback.format_exc())
|
||||||
|
logging.__getattribute__(level)(exception.__str__()) # TODO: make it so it doesn't delete line breaks
|
||||||
if level in ["critical", "error"]:
|
if level in ["critical", "error"]:
|
||||||
print("An unrecoverable error occurred, please check the log file for more information.")
|
print("An unrecoverable error occurred, please check the log file for more information.")
|
||||||
sys.exit() # could also re-raise the exception
|
sys.exit() # could also re-raise the exception
|
||||||
|
|
@ -70,6 +72,23 @@ def log_exception(exception, level="ERROR"):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def dict_check(dic, *args):
|
||||||
|
"""
|
||||||
|
Helper function to test existence within a dictionary.
|
||||||
|
:param dic: The dictionary of dictionaries to check
|
||||||
|
:param args: Any number of keys to check the dictionaries for
|
||||||
|
:return: A table of Booleans for every key checked.
|
||||||
|
"""
|
||||||
|
output = [False for _ in args]
|
||||||
|
for i in range(len(args)):
|
||||||
|
if args[i] in dic:
|
||||||
|
output[i] = True
|
||||||
|
dic = dic[args[i]]
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
class ParsingError(Exception):
|
class ParsingError(Exception):
|
||||||
"""
|
"""
|
||||||
Exception class for parsing errors
|
Exception class for parsing errors
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue