Skip to content

Commit

Permalink
Get underlying error when conversion fails
Browse files Browse the repository at this point in the history
When we get an early EOF from the converter process, we should
immediately get the exit code of that process, to find out the actual
underlying error. Currently, the exception we raise masks the underlying
error.

Raise a ConverterProcException, that in turns makes our error handling
code read the exit code of the spawned process, and converts it to a
helpful error message.

Fixes #714
  • Loading branch information
apyrgio committed Feb 15, 2024
1 parent 4407cde commit 1717294
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 13 deletions.
9 changes: 0 additions & 9 deletions dangerzone/conversion/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@
MAX_PAGE_HEIGHT = 10000


class InterruptedConversionException(Exception):
"""Data received was less than expected"""

def __init__(self) -> None:
super().__init__(
"Something interrupted the conversion and it could not be completed."
)


class ConverterProcException(Exception):
"""Some exception occurred in the converter"""

Expand Down
4 changes: 2 additions & 2 deletions dangerzone/isolation_provider/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def read_bytes(f: IO[bytes], size: int, exact: bool = True) -> bytes:
"""Read bytes from a file-like object."""
buf = f.read(size)
if exact and len(buf) != size:
raise errors.InterruptedConversionException()
raise errors.ConverterProcException()
return buf


def read_int(f: IO[bytes]) -> int:
"""Read 2 bytes from a file-like object, and decode them as int."""
untrusted_int = f.read(INT_BYTES)
if len(untrusted_int) != INT_BYTES:
raise errors.InterruptedConversionException()
raise errors.ConverterProcException()
return int.from_bytes(untrusted_int, "big", signed=False)


Expand Down
2 changes: 1 addition & 1 deletion tests/isolation_provider/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def start_doc_to_pixels_proc() -> subprocess.Popen:
monkeypatch.setattr(
provider, "start_doc_to_pixels_proc", start_doc_to_pixels_proc
)
with pytest.raises(errors.InterruptedConversionException):
with pytest.raises(errors.ConverterProcException):
provider.doc_to_pixels(doc, tmpdir)
assert provider.get_proc_exception(proc) == errors.MaxPagesException # type: ignore [arg-type]

Expand Down
2 changes: 1 addition & 1 deletion tests/isolation_provider/test_qubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def start_doc_to_pixels_proc() -> subprocess.Popen:
provider, "start_doc_to_pixels_proc", start_doc_to_pixels_proc
)

with pytest.raises(errors.InterruptedConversionException) as e:
with pytest.raises(errors.ConverterProcException) as e:
doc = Document(sample_doc)
provider.doc_to_pixels(doc, tmpdir)
assert provider.get_proc_exception(proc) == errors.QubesQrexecFailed # type: ignore [arg-type]

0 comments on commit 1717294

Please sign in to comment.