Work to get exceptions propagating correctly.

这个提交包含在:
Craig Warren
2019-12-09 17:06:32 +00:00
父节点 a2bc6829c6
当前提交 973b26a430
共有 2 个文件被更改,包括 17 次插入14 次删除

查看文件

@@ -17,33 +17,28 @@
# along with gprMax. If not, see <http://www.gnu.org/licenses/>. # along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import logging import logging
import sys
from colorama import init from colorama import init
from colorama import Fore from colorama import Fore
init() init()
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
sys.tracebacklimit = None
class GeneralError(ValueError): class GeneralError(ValueError):
"""Handles general errors. Subclasses the ValueError class.""" """Handles general errors. Subclasses the ValueError class."""
def __init__(self, message, *args): def __init__(self, message, *args):
self.message = message self.message = message
super(GeneralError, self).__init__(message, *args) super(GeneralError, self).__init__(message, *args)
log.exception(Fore.RED) log.exception(Fore.RED)
class CmdInputError(ValueError): class CmdInputError(Exception):
"""Handles errors in user specified commands. Subclasses the ValueError """Handles errors in user specified commands. Subclasses the ValueError
class. class.
""" """
pass
def __init__(self, message, *args): # def __init__(self, message, *args):
# self.message = message
self.message = message # super(CmdInputError, self).__init__(message, *args)
super(CmdInputError, self).__init__(message, *args) # log.exception(Fore.RED)
log.exception(Fore.RED)

查看文件

@@ -22,6 +22,9 @@ import logging
from .config_parser import write_simulation_config from .config_parser import write_simulation_config
from .contexts import create_context from .contexts import create_context
# Configure logging
log = logging.getLogger(__name__)
# logging.basicConfig(level=logging.DEBUG, format='%(module)s %(lineno)d %(message)s')
logging.basicConfig(level=logging.INFO, format='%(message)s') logging.basicConfig(level=logging.INFO, format='%(message)s')
@@ -133,7 +136,10 @@ def run(
args.geometry_fixed = geometry_fixed args.geometry_fixed = geometry_fixed
args.write_processed = write_processed args.write_processed = write_processed
try:
run_main(args) run_main(args)
except Exception:
log.exception('Error from main API function', exc_info=True)
def main(): def main():
@@ -154,8 +160,10 @@ def main():
parser.add_argument('--write-processed', action='store_true', default=False, help='flag to write an input file after any Python code and include commands in the original input file have been processed') parser.add_argument('--write-processed', action='store_true', default=False, help='flag to write an input file after any Python code and include commands in the original input file have been processed')
args = parser.parse_args() args = parser.parse_args()
try:
run_main(args) run_main(args)
except Exception:
log.exception('Error from main CLI function', exc_info=True)
def run_main(args): def run_main(args):
"""Called by either run (API) or main (CLI). """Called by either run (API) or main (CLI).