mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 02:12:36 +02:00
Add error code for unexpected errors in conversion
This commit is contained in:
parent
8e4f04a52e
commit
94f569cdf5
3 changed files with 13 additions and 4 deletions
|
@ -373,9 +373,9 @@ async def main() -> int:
|
||||||
error_code = 0 # Success!
|
error_code = 0 # Success!
|
||||||
except errors.ConversionException as e: # Expected Errors
|
except errors.ConversionException as e: # Expected Errors
|
||||||
error_code = e.error_code
|
error_code = e.error_code
|
||||||
except (RuntimeError, TimeoutError, ValueError) as e: # Unexpected Errors
|
except Exception as e:
|
||||||
converter.update_progress(str(e), error=True)
|
converter.update_progress(str(e), error=True)
|
||||||
error_code = 1
|
error_code = errors.UnexpectedConversionError.error_code
|
||||||
if not running_on_qubes():
|
if not running_on_qubes():
|
||||||
# Write debug information (containers version)
|
# Write debug information (containers version)
|
||||||
with open("/tmp/dangerzone/captured_output.txt", "wb") as container_log:
|
with open("/tmp/dangerzone/captured_output.txt", "wb") as container_log:
|
||||||
|
|
|
@ -72,9 +72,12 @@ async def main() -> None:
|
||||||
converter = DocumentToPixels()
|
converter = DocumentToPixels()
|
||||||
await converter.convert()
|
await converter.convert()
|
||||||
except errors.ConversionException as e:
|
except errors.ConversionException as e:
|
||||||
|
await write_bytes(str(e).encode(), file=sys.stderr)
|
||||||
sys.exit(e.error_code)
|
sys.exit(e.error_code)
|
||||||
except (RuntimeError, TimeoutError, ValueError) as e:
|
except Exception as e:
|
||||||
sys.exit(1)
|
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")))
|
num_pages = len(list(out_dir.glob("*.rgb")))
|
||||||
await write_int(num_pages)
|
await write_int(num_pages)
|
||||||
|
|
|
@ -3,6 +3,7 @@ from typing import List, Optional, Type
|
||||||
# XXX: errors start at 128 for conversion-related issues
|
# XXX: errors start at 128 for conversion-related issues
|
||||||
ERROR_SHIFT = 128
|
ERROR_SHIFT = 128
|
||||||
|
|
||||||
|
|
||||||
class ConversionException(Exception):
|
class ConversionException(Exception):
|
||||||
error_message = "Unspecified error"
|
error_message = "Unspecified error"
|
||||||
error_code = ERROR_SHIFT
|
error_code = ERROR_SHIFT
|
||||||
|
@ -67,6 +68,11 @@ class PDFtoPPMInvalidDepth(PDFtoPPMException):
|
||||||
error_message = "Error converting PDF to Pixels (Invalid PPM depth)"
|
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]:
|
def exception_from_error_code(error_code: int) -> Optional[ConversionException]:
|
||||||
"""returns the conversion exception corresponding to the error code"""
|
"""returns the conversion exception corresponding to the error code"""
|
||||||
for cls in ConversionException.get_subclasses():
|
for cls in ConversionException.get_subclasses():
|
||||||
|
|
Loading…
Reference in a new issue