From 18b73d94b0b0eb5a1dc7d990ca64885f4963cdad Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Tue, 26 Sep 2023 16:34:37 +0300 Subject: [PATCH] qubes: Find out reason of interrupted conversions 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. --- dangerzone/isolation_provider/qubes.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/dangerzone/isolation_provider/qubes.py b/dangerzone/isolation_provider/qubes.py index 36ff5ec..01214df 100644 --- a/dangerzone/isolation_provider/qubes.py +++ b/dangerzone/isolation_provider/qubes.py @@ -68,7 +68,7 @@ class Qubes(IsolationProvider): def install(self) -> bool: return True - def _convert( + def __convert( self, document: Document, ocr_lang: Optional[str] = None, @@ -124,13 +124,7 @@ class Qubes(IsolationProvider): 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 @@ -194,6 +188,19 @@ class Qubes(IsolationProvider): 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