Skip to content

Commit

Permalink
Added try excepts for unhandled exceptions
Browse files Browse the repository at this point in the history
Fixes #776
  • Loading branch information
amnak613 authored and apyrgio committed Sep 17, 2024
1 parent d7f8096 commit 9b9e265
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
16 changes: 11 additions & 5 deletions dangerzone/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,17 @@ def convert_documents(
self, ocr_lang: Optional[str], stdout_callback: Optional[Callable] = None
) -> None:
def convert_doc(document: Document) -> None:
self.isolation_provider.convert(
document,
ocr_lang,
stdout_callback,
)
try:
self.isolation_provider.convert(
document,
ocr_lang,
stdout_callback,
)
except Exception as e:
log.exception(
f"Unexpected error occurred while converting '{document}'"
)
document.mark_as_failed()

max_jobs = self.isolation_provider.get_max_parallel_conversions()
with concurrent.futures.ThreadPoolExecutor(max_workers=max_jobs) as executor:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from dangerzone.cli import cli_main, display_banner
from dangerzone.document import ARCHIVE_SUBDIR, SAFE_EXTENSION
from dangerzone.isolation_provider.qubes import is_qubes_native_conversion
from dangerzone.util import get_resource_path

from .conftest import for_each_doc, for_each_external_doc

Expand Down Expand Up @@ -219,6 +220,20 @@ def test_output_filename_uncommon(
result = self.run_cli([sample_pdf, "--output-filename", output_filename])
result.assert_success()

### Test method for swallowed exception
def test_output_filename_same_file_dummy_fails(self) -> None:
resource_path = get_resource_path("dummy_document.pdf")
# Using the same filename for both input and output should fail.
result = self.run_cli(
[
resource_path,
"--output-filename",
resource_path,
"--unsafe-dummy-conversion",
]
)
result.assert_failure()

def test_output_filename_new_dir(self, sample_pdf: str) -> None:
output_filename = str(Path("fake-directory") / "my-output.pdf")
result = self.run_cli([sample_pdf, "--output-filename", output_filename])
Expand Down

0 comments on commit 9b9e265

Please sign in to comment.