Add error code for unexpected errors in conversion

This commit is contained in:
deeplow 2023-09-12 13:39:31 +01:00
parent 8e4f04a52e
commit 94f569cdf5
No known key found for this signature in database
GPG key ID: 577982871529A52A
3 changed files with 13 additions and 4 deletions

View file

@ -373,9 +373,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:

View file

@ -72,9 +72,12 @@ async def main() -> None:
converter = DocumentToPixels()
await converter.convert()
except errors.ConversionException as e:
await write_bytes(str(e).encode(), 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).encode(), 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)

View file

@ -3,6 +3,7 @@ from typing import List, Optional, Type
# XXX: errors start at 128 for conversion-related issues
ERROR_SHIFT = 128
class ConversionException(Exception):
error_message = "Unspecified error"
error_code = ERROR_SHIFT
@ -67,6 +68,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():