Skip to content

Commit

Permalink
qubes: Find out reason of interrupted conversions
Browse files Browse the repository at this point in the history
If a conversion has been interrupted (usually due to an EOF), figure out
why this happened by checking the exit code of the spawned process.
  • Loading branch information
apyrgio committed Sep 26, 2023
1 parent 30196ff commit 18b73d9
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions dangerzone/isolation_provider/qubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self) -> None:
def install(self) -> bool:
return True

def _convert(
def __convert(
self,
document: Document,
ocr_lang: Optional[str] = None,
Expand Down Expand Up @@ -124,13 +124,7 @@ def _convert(
assert self.proc.stdout is not None
os.set_blocking(self.proc.stdout.fileno(), False)

try:
n_pages = read_int(self.proc.stdout, timeout)
except errors.InterruptedConversion:
error_code = p.wait()
# XXX Reconstruct exception from error code
raise exception_from_error_code(error_code) # type: ignore [misc]

n_pages = read_int(self.proc.stdout, timeout)
if n_pages == 0:
# FIXME: Fail loudly in that case
return False
Expand Down Expand Up @@ -194,6 +188,19 @@ def print_progress_wrapper(error: bool, text: str, percentage: float) -> None:

return success

def _convert(
self,
document: Document,
ocr_lang: Optional[str] = None,
) -> bool:
try:
return self.__convert(document, ocr_lang)
except errors.InterruptedConversion:
assert self.proc is not None
error_code = self.proc.wait(3)
# XXX Reconstruct exception from error code
raise errors.exception_from_error_code(error_code) # type: ignore [misc]

def get_max_parallel_conversions(self) -> int:
return 1

Expand Down

0 comments on commit 18b73d9

Please sign in to comment.