Skip to content

Commit

Permalink
Wrap functions in decorator which catches exceptions and posts them t…
Browse files Browse the repository at this point in the history
…o GH
  • Loading branch information
simoncozens committed Sep 1, 2023
1 parent 52c2ef2 commit 60f6ef1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Lib/gftools/qa.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import os
import subprocess
import traceback

from gftools.gfgithub import GitHubClient
from gftools.utils import mkdir
Expand All @@ -20,13 +21,28 @@
logger.setLevel(logging.INFO)


def report_exceptions(meth):
def safe_call(self, *args, **kwargs):
try:
meth(self, *args, **kwargs)
except Exception as e:
msg = f"Call to {meth.__name__} failed:\n{e}"
print(msg)
print()
print(traceback.format_exc())
self.post_to_github(msg+"\n\n"+"See CI logs for more details")

return safe_call


class FontQA:
def __init__(self, fonts, fonts_before=None, out="out", url=None):
self.fonts = fonts
self.fonts_before = fonts_before
self.out = out
self.url = url

@report_exceptions
def diffenator(self, **kwargs):
logger.info("Running Diffenator")
if not self.fonts_before:
Expand All @@ -44,6 +60,7 @@ def diffenator(self, **kwargs):
diffbrowsers=False,
)

@report_exceptions
def diffbrowsers(self, imgs=False):
logger.info("Running Diffbrowsers")
if not self.fonts_before:
Expand All @@ -62,6 +79,7 @@ def diffbrowsers(self, imgs=False):
diffbrowsers=True,
)

@report_exceptions
def proof(self, imgs=False):
logger.info("Running proofing tools")
dst = os.path.join(self.out, "Proof")
Expand All @@ -73,6 +91,7 @@ def proof(self, imgs=False):
filter_styles=None,
)

@report_exceptions
def fontbakery(self, profile="googlefonts", html=False, extra_args=None):
logger.info("Running Fontbakery")
out = os.path.join(self.out, "Fontbakery")
Expand Down

0 comments on commit 60f6ef1

Please sign in to comment.