Skip to content

Commit

Permalink
more specific exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kreuzberger authored and danwos committed Aug 23, 2023
1 parent da2ad00 commit 81ac559
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sphinx_simplepdf/builders/simplepdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def finish(self) -> None:

else:
retries = self.config["simplepdf_weasyprint_retries"]
success = False
for n in range(1 + retries):
try:
wp_out = subprocess.check_output(args, timeout=timeout, text=True, stderr=subprocess.STDOUT)
Expand All @@ -152,11 +153,14 @@ def finish(self) -> None:
pass
else:
print(line)
success = True
break
except: # subprocess.TimeoutExpired or subprocess.CalledProcessError
logger.warning(f"exception in weasyprint, retrying")

if n == retries - 1:
except subprocess.TimeoutExpired:
logger.warning(f"TimeoutExpired in weasyprint, retrying")
except subprocess.CalledProcessError as e:
logger.warning(f"CalledProcessError in weasyprint, retrying\n{str(e)}")
finally:
if (n == retries - 1) and not success:
raise RuntimeError(f"maximum number of retries {retries} failed in weasyprint")

def _toctree_fix(self, html):
Expand Down

0 comments on commit 81ac559

Please sign in to comment.