mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 02:12:36 +02:00
errors: Add error for interrupted conversions
Add an error for interrupted conversions, in order to better differentiate this scenario from other ValueErrors that may be raised throughout the code's lifetime.
This commit is contained in:
parent
0273522fb1
commit
30196ff35b
2 changed files with 12 additions and 3 deletions
|
@ -68,6 +68,15 @@ class PDFtoPPMInvalidDepth(PDFtoPPMException):
|
||||||
error_message = "Error converting PDF to Pixels (Invalid PPM depth)"
|
error_message = "Error converting PDF to Pixels (Invalid PPM depth)"
|
||||||
|
|
||||||
|
|
||||||
|
class InterruptedConversion(ConversionException):
|
||||||
|
"""Protocol received num of bytes different than expected"""
|
||||||
|
|
||||||
|
error_code = ERROR_SHIFT + 60
|
||||||
|
error_message = (
|
||||||
|
"Something interrupted the conversion and it could not be completed."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class UnexpectedConversionError(PDFtoPPMException):
|
class UnexpectedConversionError(PDFtoPPMException):
|
||||||
error_code = ERROR_SHIFT + 100
|
error_code = ERROR_SHIFT + 100
|
||||||
error_message = "Some unexpected error occurred while converting the document"
|
error_message = "Some unexpected error occurred while converting the document"
|
||||||
|
|
|
@ -13,8 +13,8 @@ import zipfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import IO, Callable, Optional
|
from typing import IO, Callable, Optional
|
||||||
|
|
||||||
|
from ..conversion import errors
|
||||||
from ..conversion.common import calculate_timeout, running_on_qubes
|
from ..conversion.common import calculate_timeout, running_on_qubes
|
||||||
from ..conversion.errors import exception_from_error_code
|
|
||||||
from ..conversion.pixels_to_pdf import PixelsToPDF
|
from ..conversion.pixels_to_pdf import PixelsToPDF
|
||||||
from ..document import Document
|
from ..document import Document
|
||||||
from ..util import (
|
from ..util import (
|
||||||
|
@ -41,7 +41,7 @@ def read_bytes(f: IO[bytes], size: int, timeout: float, exact: bool = True) -> b
|
||||||
"""Read bytes from a file-like object."""
|
"""Read bytes from a file-like object."""
|
||||||
buf = nonblocking_read(f, size, timeout)
|
buf = nonblocking_read(f, size, timeout)
|
||||||
if exact and len(buf) != size:
|
if exact and len(buf) != size:
|
||||||
raise ValueError("Did not receive exact number of bytes")
|
raise errors.InterruptedConversion
|
||||||
return buf
|
return buf
|
||||||
|
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ class Qubes(IsolationProvider):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
n_pages = read_int(self.proc.stdout, timeout)
|
n_pages = read_int(self.proc.stdout, timeout)
|
||||||
except ValueError:
|
except errors.InterruptedConversion:
|
||||||
error_code = p.wait()
|
error_code = p.wait()
|
||||||
# XXX Reconstruct exception from error code
|
# XXX Reconstruct exception from error code
|
||||||
raise exception_from_error_code(error_code) # type: ignore [misc]
|
raise exception_from_error_code(error_code) # type: ignore [misc]
|
||||||
|
|
Loading…
Reference in a new issue