Skip to content

Commit

Permalink
improve exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Nfsaavedra committed Apr 29, 2024
1 parent 93fa151 commit 87b3aa1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion glitch/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
import traceback

from typing import List

EXCEPTIONS = {
"ANSIBLE_PLAYBOOK": "Ansible - File is not a playbook: {}",
"ANSIBLE_TASKS_FILE": "Ansible - File is not a tasks file: {}",
Expand All @@ -20,5 +22,8 @@
def throw_exception(exception: str, *args: str) -> None:
print("Error:", exception.format(*args), file=sys.stderr)
print("=" * 20 + " Traceback " + "=" * 20, file=sys.stderr)
traceback.print_exc(file=sys.stderr)
exc: List[str] = traceback.format_exc().split("\n")
if len(exc) > 40:
exc = exc[:20] + ["..."] + exc[-20:]
print("\n".join(exc), file=sys.stderr)
print("=" * 51, file=sys.stderr)

0 comments on commit 87b3aa1

Please sign in to comment.