Skip to content

Commit

Permalink
Progresss
Browse files Browse the repository at this point in the history
  • Loading branch information
hwikle-lanl committed Dec 5, 2024
1 parent f29d799 commit 288cd8b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
30 changes: 27 additions & 3 deletions lib/pavilion/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
import shutil
import traceback

from traceback import format_exception
from typing import List

import lark

import yc_yaml

from pavilion.micro import flatten


class PavilionError(RuntimeError):
"""Base class for all Pavilion errors."""
Expand Down Expand Up @@ -47,12 +52,31 @@ def __str__(self):
else:
return self.msg

def pformat(self) -> str:
"""Specially format the exception for printing."""
@staticmethod
def _wrap_lines(lines: List[str], width: int) -> List[str]:
"""Given a list of lines, produce a new list of lines wrapped to the specified width."""

lines = map(lambda x: textwrap.wrap(x, width=width), lines)

return list(flatten(lines))


def pformat(self, traceback: bool = False) -> 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:
lines = self._wrap_lines(format_exception(self))

# Remove newlines, for consistency with textwrap.wrap
map(lambda x: x.rstrip("\n"), lines)

return "\n".join(lines)

lines = []
next_exc = self.prior_error
width = shutil.get_terminal_size((80, 80)).columns
tab_level = 0
for line in str(self.msg).split('\n'):
lines.extend(textwrap.wrap(line, width=width))
Expand Down
4 changes: 2 additions & 2 deletions lib/pavilion/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def main():
if not '--show-tracebacks' in sys.argv:
output.fprint(sys.stderr, "Error getting config, exiting.", err, color=output.RED)
else:
print(traceback.format_exc())
PavilionError(err).pformat(traceback=True)

sys.exit(-1)

Expand All @@ -68,7 +68,7 @@ def main():
if not partial_args.show_tracebacks:
output.fprint(sys.stderr, "Error initializing plugins.", err, color=output.RED)
else:
print(traceback.format_exc())
PavilionError(err).pformat(traceback=True)

sys.exit(-1)

Expand Down

0 comments on commit 288cd8b

Please sign in to comment.