From 2eec46c18436402b432457da6277d0f837f1d8df Mon Sep 17 00:00:00 2001 From: Hank Wikle Date: Fri, 6 Dec 2024 13:40:25 -0700 Subject: [PATCH] Add option to print full traceback to error class --- lib/pavilion/cmd_utils.py | 2 +- lib/pavilion/commands/group.py | 6 ++++-- lib/pavilion/errors.py | 7 +++++-- lib/pavilion/series/test_set.py | 16 +++++----------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/pavilion/cmd_utils.py b/lib/pavilion/cmd_utils.py index e1ce127c0..b6dcdfed7 100644 --- a/lib/pavilion/cmd_utils.py +++ b/lib/pavilion/cmd_utils.py @@ -321,7 +321,7 @@ def get_collection_path(pav_cfg, collection) -> Union[Path, None]: return None -def test_list_to_paths(pav_cfg: config.PavConfig, req_tests: List, +def test_list_to_paths(pav_cfg: config.PavConfig, req_tests: List[str], errfile: Optional[Path] = None) -> List[Path]: """Given a list of raw test id's and series id's, return a list of paths to those tests. diff --git a/lib/pavilion/commands/group.py b/lib/pavilion/commands/group.py index 88bf20146..2f6581e63 100644 --- a/lib/pavilion/commands/group.py +++ b/lib/pavilion/commands/group.py @@ -2,6 +2,7 @@ import errno import fnmatch +from typing import Optional from pavilion import groups from pavilion import config @@ -122,7 +123,7 @@ def run(self, pav_cfg, args): return self._run_sub_command(pav_cfg, args) - def _get_group(self, pav_cfg: config.PavConfig, group_name: str) -> TestGroup: + def _get_group(self, pav_cfg: config.PavConfig, group_name: str) -> Optional[TestGroup]: """Get the requested group, and print a standard error message on failure.""" try: @@ -131,13 +132,14 @@ def _get_group(self, pav_cfg: config.PavConfig, group_name: str) -> TestGroup: fprint(self.errfile, "Error loading group '{}'", color=output.RED) fprint(self.errfile, err.pformat()) - raise err + return None if not group.exists(): fprint(self.errfile, "Group '{}' does not exist.\n Looked here:" .format(group_name), color=output.RED) fprint(self.errfile, " " + group.path.as_posix()) + return None return group diff --git a/lib/pavilion/errors.py b/lib/pavilion/errors.py index 3b90f6450..c1ed2a80d 100644 --- a/lib/pavilion/errors.py +++ b/lib/pavilion/errors.py @@ -23,6 +23,9 @@ class PavilionError(RuntimeError): SPLIT_RE = re.compile(': *\n? *') TAB_LEVEL = ' ' + # Set traceback behavior for all instances + show_tracebacks = False + def __init__(self, msg, prior_error=None, data=None): """These take a new message and whatever prior error caused the problem. @@ -61,13 +64,13 @@ def _wrap_lines(lines: List[str], width: int) -> List[str]: return list(flatten(lines)) - def pformat(self, traceback: bool = False) -> str: + def pformat(self) -> str: """Specially format the exception for printing. If traceback is True, return the full traceback associated with the error. Otherwise, return a summary of the error.""" width = shutil.get_terminal_size((80, 80)).columns - if traceback: + if PavilionError.show_tracebacks: lines = self._wrap_lines(format_exception(self)) # Remove newlines, for consistency with textwrap.wrap diff --git a/lib/pavilion/series/test_set.py b/lib/pavilion/series/test_set.py index 38b0e10eb..533318de3 100644 --- a/lib/pavilion/series/test_set.py +++ b/lib/pavilion/series/test_set.py @@ -189,9 +189,8 @@ def __ordered_split(self) -> List['TestSet']: return test_sets - def make_iter(self, build_only: bool = False, rebuild: bool = False, - local_builds_only: bool = False, - show_tracebacks: bool = False) -> Iterator[List[TestRun]]: + def make_iter(self, build_only=False, rebuild=False, local_builds_only=False) \ + -> Iterator[List[TestRun]]: """Resolve the given tests names and options into actual test run objects, and print the test creation status. This returns an iterator over batches tests, respecting the batch_size (half the simultanious limit). @@ -238,20 +237,15 @@ def make_iter(self, build_only: bool = False, rebuild: bool = False, for error in cfg_resolver.errors: if error.request is not None: self.status.set(S_STATES.ERROR, - '{} - {}'.format( - error.request.request, - error.pformat(show_tracebacks))) - + '{} - {}'.format(error.request.request, error.pformat())) output.fprint( self.outfile, - "{} - {}".format( - error.request.request, - error.pformat(show_tracebacks))) + "{} - {}".format(error.request.request, error.pformat())) else: self.status.set(S_STATES.ERROR, error.pformat()) output.fprint( self.outfile, - "{}".format(error.pformat(show_tracebacks))) + "{}".format(error.pformat())) if not self.ignore_errors: raise TestSetError("Error creating tests for test set {}.".format(self.name),