From 2a249397ad8356e34f20be6493e4a988724a1112 Mon Sep 17 00:00:00 2001 From: Ro Date: Tue, 9 Jul 2024 16:31:10 -0400 Subject: [PATCH] Isolate print_preflight status --- client/securedrop_client/export.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/client/securedrop_client/export.py b/client/securedrop_client/export.py index d06ea4329..85fc3c923 100644 --- a/client/securedrop_client/export.py +++ b/client/securedrop_client/export.py @@ -240,19 +240,28 @@ def _on_print_preflight_complete(self) -> None: """ self._cleanup_tmpdir() if self.process: - output = self.process.readAllStandardError().data().decode("utf-8").strip() + output_untrusted = self.process.readAllStandardError().data().decode("utf-8").strip() try: - status = ExportStatus(output) - if status == ExportStatus.PRINT_PREFLIGHT_SUCCESS: - self.print_preflight_check_succeeded.emit(status) - logger.debug("Print preflight success") + if output_untrusted: + logger.debug(f"Result is {output_untrusted}") + + # The final line of stderr is the status. + status_string_untrusted = output_untrusted.split("\n")[-1] + status = ExportStatus(status_string_untrusted) + + if status == ExportStatus.PRINT_PREFLIGHT_SUCCESS: + logger.debug("Print preflight success") + self.print_preflight_check_succeeded.emit(status) + else: + logger.debug(f"Print preflight failure ({status.value})") + self.print_preflight_check_failed.emit(ExportError(status)) else: - logger.debug(f"Print preflight failure ({status.value})") - self.print_preflight_check_failed.emit(ExportError(status)) + logger.error("Export preflight returned empty result") + self.print_preflight_check_failed.emit(ExportError(ExportStatus.ERROR_PRINT)) - except ValueError as error: - logger.debug(f"Print preflight check failed: {error}") - logger.error("Print preflight check failed") + except ValueError as e: + logger.debug(f"Export preflight returned unexpected value: {e}") + logger.error("Export preflight returned unexpected value") self.print_preflight_check_failed.emit(ExportError(ExportStatus.ERROR_PRINT)) def _on_print_prefight_error(self) -> None: