Skip to content

Commit

Permalink
Add error code for unexpected errors in conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
deeplow committed Sep 12, 2023
1 parent 628cadf commit 5853356
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions dangerzone/conversion/doc_to_pixels.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,9 @@ async def main() -> int:
error_code = 0 # Success!
except errors.ConversionException as e: # Expected Errors
error_code = e.error_code
except (RuntimeError, TimeoutError, ValueError) as e: # Unexpected Errors
except Exception as e:
converter.update_progress(str(e), error=True)
error_code = 1
error_code = errors.UnexpectedConversionError.error_code
if not running_on_qubes():
# Write debug information (containers version)
with open("/tmp/dangerzone/captured_output.txt", "wb") as container_log:
Expand Down
7 changes: 5 additions & 2 deletions dangerzone/conversion/doc_to_pixels_qubes_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ async def main() -> None:
converter = DocumentToPixels()
await converter.convert()
except errors.ConversionException as e:
await write_bytes(str(e), file=sys.stderr)
sys.exit(e.error_code)
except (RuntimeError, TimeoutError, ValueError) as e:
sys.exit(1)
except Exception as e:
await write_bytes(str(e), file=sys.stderr)
error_code = errors.UnexpectedConversionError.error_code
sys.exit(error_code)

num_pages = len(list(out_dir.glob("*.rgb")))
await write_int(num_pages)
Expand Down
6 changes: 6 additions & 0 deletions dangerzone/conversion/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# XXX: errors start at 128 for conversion-related issues
ERROR_SHIFT = 128


class ConversionException(Exception):
error_message = "Unspecified error"
error_code = ERROR_SHIFT
Expand Down Expand Up @@ -72,6 +73,11 @@ class PDFtoPPMInvalidDepth(PDFtoPPMException):
error_message = "Error converting PDF to Pixels (Invalid PPM depth)"


class UnexpectedConversionError(PDFtoPPMException):
error_code = ERROR_SHIFT + 100
error_message = "Some unxpected error occured while converting the document"


def exception_from_error_code(error_code: int) -> Optional[ConversionException]:
"""returns the conversion exception corresponding to the error code"""
for cls in ConversionException.get_subclasses():
Expand Down

0 comments on commit 5853356

Please sign in to comment.