Device-Type-Library-Import/exception_handler.py
Daniel W. Anner 4fca4a7fb4
Cleanup (#75)
* - Added exception handler function with easy map dictionary.
- Added extra default values for ENV vars.
- Moved parser args to Settings for global use.
- Started implementing new exception handler
- Moved git functions to gitcmd.py.
- Implemented exception handler for git functions.
- Removed extra imports where no longer needed.

* Added how to fix ssl error in case it pops up

* - Removed circular import of settings.py and gitcmd.py
- Added exception_handler.py to handle exceptions (refer to above)
- Made GitCMD a class with init and run methods
- Removed git completely from nb-dt-import.py

* Fixed missing arg

* made exception handler a class to prevent circular import
2023-03-03 16:03:17 -05:00

28 lines
964 B
Python

from sys import exit as system_exit
class ExceptionHandler:
def __new__(cls, *args, **kwargs):
return super().__new__(cls)
def __init__(self, args):
self.args = args
def exception(self, exception_type, exception, stack_trace=None):
exception_dict = {
"EnvironmentError": f'Environment variable "{exception}" is not set.',
"SSLError": f'SSL verification failed. IGNORE_SSL_ERRORS is {exception}. Set IGNORE_SSL_ERRORS to True if you want to ignore this error. EXITING.',
"GitCommandError": f'The repo "{exception}" is not a valid git repo.',
"GitInvalidRepositoryError": f'The repo "{exception}" is not a valid git repo.',
"Exception": f'An unknown error occurred: "{exception}"'
}
if self.args.verbose and stack_trace:
print(stack_trace)
print(exception_dict[exception_type])
system_exit(1)