Skip to content

Commit

Permalink
Add option to print full traceback to error class
Browse files Browse the repository at this point in the history
  • Loading branch information
hwikle-lanl committed Dec 6, 2024
1 parent ef6e673 commit 2eec46c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/pavilion/cmd_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions lib/pavilion/commands/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import errno
import fnmatch
from typing import Optional

from pavilion import groups
from pavilion import config
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lib/pavilion/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
16 changes: 5 additions & 11 deletions lib/pavilion/series/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 2eec46c

Please sign in to comment.