diff --git a/colcon_core/executor/sequential.py b/colcon_core/executor/sequential.py index 8f078b63..b3bc3cab 100644 --- a/colcon_core/executor/sequential.py +++ b/colcon_core/executor/sequential.py @@ -5,7 +5,6 @@ import logging import signal import sys -import traceback from colcon_core.executor import ExecutorExtensionPoint from colcon_core.executor import OnError @@ -68,10 +67,9 @@ def execute(self, args, jobs, *, on_error=OnError.interrupt): # noqa: D102 "run_until_complete '{name}' finished" .format_map(locals())) return signal.SIGINT - except Exception as e: # noqa: F841 - exc = traceback.format_exc() - logger.error( - "Exception in job execution '{name}': {e}\n{exc}" + except Exception: + logger.exception( + "Exception in job execution '{name}'" .format_map(locals())) return 1 result = future.result() diff --git a/colcon_core/plugin_system.py b/colcon_core/plugin_system.py index 5dfa8a17..a2817d2f 100644 --- a/colcon_core/plugin_system.py +++ b/colcon_core/plugin_system.py @@ -2,7 +2,6 @@ # Licensed under the Apache License, Version 2.0 from collections import OrderedDict -import traceback from colcon_core.entry_point import load_entry_points from colcon_core.logging import colcon_logger @@ -65,12 +64,11 @@ def _instantiate_extension( "Skipping extension '{group_name}.{extension_name}': {e}" .format_map(locals())) extension_instance = None - except Exception as e: # noqa: F841 + except Exception: # catch exceptions raised in extension constructor - exc = traceback.format_exc() - logger.error( + logger.exception( 'Exception instantiating extension ' - "'{group_name}.{extension_name}': {e}\n{exc}".format_map(locals())) + "'{group_name}.{extension_name}'".format_map(locals())) extension_instance = None if not unique_instance: _extension_instances[extension_class] = extension_instance diff --git a/colcon_core/task/python/test/__init__.py b/colcon_core/task/python/test/__init__.py index d61e529a..050f2551 100644 --- a/colcon_core/task/python/test/__init__.py +++ b/colcon_core/task/python/test/__init__.py @@ -2,7 +2,6 @@ # Licensed under the Apache License, Version 2.0 import re -import traceback from colcon_core.logging import colcon_logger from colcon_core.plugin_system import get_first_line_doc @@ -27,7 +26,6 @@ def add_arguments(self, *, parser): # noqa: D102 add_python_testing_step_arguments(parser) async def test(self, *, additional_hooks=None): # noqa: D102 - pkg = self.context.pkg args = self.context.args logger.info( @@ -36,8 +34,8 @@ async def test(self, *, additional_hooks=None): # noqa: D102 try: env = await get_command_environment( 'setup_py', args.build_base, self.context.dependencies) - except RuntimeError as e: - logger.error(str(e)) + except RuntimeError: + logger.exception('Failed to get command environment') return 1 setup_py_data = get_setup_data(self.context.pkg, env) @@ -52,15 +50,13 @@ async def test(self, *, additional_hooks=None): # noqa: D102 1, "test() by extension '{key}'".format_map(locals())) try: matched = extension.match(self.context, env, setup_py_data) - except Exception as e: # noqa: F841 + except Exception: # catch exceptions raised in python testing step extension - exc = traceback.format_exc() - logger.error( + logger.exception( 'Exception in Python testing step extension ' - "'{extension.STEP_TYPE}': {e}\n{exc}" + "'{extension.STEP_TYPE}'" .format_map(locals())) - # skip failing extension, continue with next one - continue + return 1 if matched: break else: @@ -73,12 +69,11 @@ async def test(self, *, additional_hooks=None): # noqa: D102 1, "test.step() by extension '{key}'".format_map(locals())) try: return await extension.step(self.context, env, setup_py_data) - except Exception as e: # noqa: F841 + except Exception: # catch exceptions raised in python testing step extension - exc = traceback.format_exc() - logger.error( + logger.exception( 'Exception in Python testing step extension ' - "'{extension.STEP_TYPE}': {e}\n{exc}".format_map(locals())) + "'{extension.STEP_TYPE}'".format_map(locals())) return 1 @@ -176,12 +171,11 @@ def add_python_testing_step_arguments(parser): try: retval = extension.add_arguments(parser=parser) assert retval is None, 'add_arguments() should return None' - except Exception as e: # noqa: F841 + except Exception: # catch exceptions raised in package selection extension - exc = traceback.format_exc() - logger.error( + logger.exception( 'Exception in Python testing step extension ' - "'{extension.STEP_TYPE}': {e}\n{exc}".format_map(locals())) + "'{extension.STEP_TYPE}'".format_map(locals())) # skip failing extension, continue with next one