Skip to content

Commit

Permalink
Verbose error handling
Browse files Browse the repository at this point in the history
* Print out tracebacks when errors occur, these were being erroneously suppressed
* Log tracebacks in reports
  • Loading branch information
bricoletc committed Mar 16, 2022
1 parent fef16f7 commit 2d3a89d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 0 additions & 1 deletion gramtools/commands/build/vcf_to_prg_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from gramtools import ENDIANNESS, BYTES_PER_INT
from gramtools.commands.common import load_fasta, int_to_bytes, integer_to_nucleotide

sys.tracebacklimit = 0
logger = logging.getLogger("vcf_to_prg_string")
logger.setLevel(logging.WARNING)

Expand Down
11 changes: 8 additions & 3 deletions gramtools/commands/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import collections
import os
import json
import traceback

from gramtools import version
from .paths import ProjectPaths
Expand All @@ -17,20 +18,24 @@ def with_report(f):
"""

def reportify(report, action: str, command_paths: ProjectPaths, *args):
success, error, error_message = True, None, None
success = True
timer_start = time.time()

try:
original_result = f(report, action, command_paths, *args)
except Exception as e:
success = False
error = e
traceback_string = "".join(
traceback.format_exception(etype=type(e), value=e, tb=e.__traceback__)
)
timer_end = time.time()

report["success"] = success
process_report = collections.OrderedDict(
{"success": success, "run_time": int(timer_end) - int(timer_start)}
)
if not success:
process_report["traceback"] = traceback_string.split("\n")

# The condition below accounts for the called function reporting as well.
if action not in report["processes"]:
Expand All @@ -42,7 +47,7 @@ def reportify(report, action: str, command_paths: ProjectPaths, *args):
} # Place success status at very top

if not success:
log.error(f"{error}")
log.error(f"Traceback: \n{traceback_string}")
log.error(
f"Unsuccessful {action}. " f"Process reported to {command_paths.report}"
)
Expand Down

0 comments on commit 2d3a89d

Please sign in to comment.